From 91fd3b772e338b7cf4f2ecc15ed81af82f939329 Mon Sep 17 00:00:00 2001 From: David Nalley Date: Mon, 2 Jul 2012 09:08:51 -0400 Subject: [PATCH] Applying patch from Prasanna Santhanam Marvin sandbox example scripts for generating one host configurations https://reviews.apache.org/r/5656 --- tools/marvin/marvin/deployDataCenter.py | 22 +-- .../marvin/sandbox/advanced/advanced_env.py | 41 ++++-- .../marvin/sandbox/advanced/setup.properties | 22 ++- .../marvin/marvin/sandbox/basic/basic_env.py | 134 ++++++++++++++++++ tools/marvin/setup.py | 2 +- 5 files changed, 190 insertions(+), 31 deletions(-) diff --git a/tools/marvin/marvin/deployDataCenter.py b/tools/marvin/marvin/deployDataCenter.py index 39b5e4e6f26..5c7880e60ae 100644 --- a/tools/marvin/marvin/deployDataCenter.py +++ b/tools/marvin/marvin/deployDataCenter.py @@ -83,7 +83,7 @@ class deployDataCenters(): primarycmd.clusterid = clusterId self.apiClient.createStoragePool(primarycmd) - def createpods(self, pods, zone, zoneId): + def createpods(self, pods, zone, zoneId, networkId=None): if pods is None: return for pod in pods: @@ -97,9 +97,9 @@ class deployDataCenters(): createpodResponse = self.apiClient.createPod(createpod) podId = createpodResponse.id - if pod.guestIpRanges is not None: + if pod.guestIpRanges is not None and networkId is not None: self.createVlanIpRanges("Basic", pod.guestIpRanges, zoneId,\ - podId) + podId, networkId) self.createClusters(pod.clusters, zoneId, podId) @@ -155,8 +155,7 @@ class deployDataCenters(): networkcmdresponse = self.apiClient.createNetwork(networkcmd) networkId = networkcmdresponse.id - - self.createVlanIpRanges(mode, ipranges, zoneId, networkId) + return networkId def createPhysicalNetwork(self, name, zoneid, vlan=None): phynet = createPhysicalNetwork.createPhysicalNetworkCmd() @@ -249,13 +248,12 @@ class deployDataCenters(): phynetwrk = self.createPhysicalNetwork(zone.name + "-pnet", \ zoneId) - self.addTrafficTypes(phynetwrk.id, ["Guest", "Public", \ - "Management"]) - self.configureProviders(phynetwrk, zone) self.updatePhysicalNetwork(phynetwrk.id, "Enabled", vlan=zone.vlan) if zone.networktype == "Basic": + self.addTrafficTypes(phynetwrk.id, ["Guest", "Management"]) + listnetworkoffering = \ listNetworkOfferings.listNetworkOfferingsCmd() @@ -271,11 +269,13 @@ class deployDataCenters(): guestntwrk.zoneid = zoneId guestntwrk.networkofferingid = \ listnetworkofferingresponse[0].id - self.createnetworks([guestntwrk], zoneId, zone.networktype) - - self.createpods(zone.pods, zone, zoneId) + networkid = self.createnetworks([guestntwrk], zoneId, zone.networktype) + self.createpods(zone.pods, zone, zoneId, networkid) if zone.networktype == "Advanced": + self.createpods(zone.pods, zone, zoneId) + self.addTrafficTypes(phynetwrk.id, ["Guest", "Public", \ + "Management"]) self.createVlanIpRanges(zone.networktype, zone.ipranges, \ zoneId) diff --git a/tools/marvin/marvin/sandbox/advanced/advanced_env.py b/tools/marvin/marvin/sandbox/advanced/advanced_env.py index 25e83dbb0f4..fa504c3890e 100644 --- a/tools/marvin/marvin/sandbox/advanced/advanced_env.py +++ b/tools/marvin/marvin/sandbox/advanced/advanced_env.py @@ -1,5 +1,20 @@ #!/usr/bin/env python - +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. ''' ############################################################ # Experimental state of scripts @@ -7,11 +22,11 @@ # * Only a sandbox ############################################################ ''' - +import random +import marvin from ConfigParser import SafeConfigParser from optparse import OptionParser -from configGenerator import * -import random +from marvin.configGenerator import * def getGlobalSettings(config): @@ -28,7 +43,7 @@ def describeResources(config): z = zone() z.dns1 = config.get('environment', 'dns') z.internaldns1 = config.get('environment', 'dns') - z.name = 'Sandbox-%s'%(config.get('environment', 'hypervisor')) + z.name = 'Sandbox-%s'%(config.get('cloudstack', 'hypervisor')) z.networktype = 'Advanced' z.guestcidraddress = '10.1.1.0/24' @@ -37,37 +52,37 @@ def describeResources(config): p.gateway = config.get('cloudstack', 'private.gateway') p.startip = config.get('cloudstack', 'private.pod.startip') p.endip = config.get('cloudstack', 'private.pod.endip') - p.netmask = '255.255.255.0' + p.netmask = config.get('cloudstack', 'private.netmask') v = iprange() v.gateway = config.get('cloudstack', 'public.gateway') v.startip = config.get('cloudstack', 'public.vlan.startip') v.endip = config.get('cloudstack', 'public.vlan.endip') - v.netmask = '255.255.255.0' + v.netmask = config.get('cloudstack', 'public.netmask') v.vlan = config.get('cloudstack', 'public.vlan') z.ipranges.append(v) c = cluster() c.clustername = 'C0' - c.hypervisor = config.get('environment', 'hypervisor') + c.hypervisor = config.get('cloudstack', 'hypervisor') c.clustertype = 'CloudManaged' h = host() h.username = 'root' - h.password = 'password' + h.password = config.get('cloudstack', 'host.password') h.url = 'http://%s'%(config.get('cloudstack', 'host')) c.hosts.append(h) ps = primaryStorage() ps.name = 'PS0' - ps.url = config.get('cloudstack', 'pool') + ps.url = config.get('cloudstack', 'primary.pool') c.primaryStorages.append(ps) p.clusters.append(c) z.pods.append(p) secondary = secondaryStorage() - secondary.url = config.get('cloudstack', 'secondary') + secondary.url = config.get('cloudstack', 'secondary.pool') z.secondaryStorages.append(secondary) '''Add zone''' @@ -80,7 +95,9 @@ def describeResources(config): '''Add a database''' db = dbServer() - db.dbSvr = config.get('environment', 'database') + db.dbSvr = config.get('environment', 'mysql.host') + db.user = config.get('environment', 'mysql.cloud.user') + db.passwd = config.get('environment', 'mysql.cloud.passwd') zs.dbSvr = db '''Add some configuration''' diff --git a/tools/marvin/marvin/sandbox/advanced/setup.properties b/tools/marvin/marvin/sandbox/advanced/setup.properties index 48b082e4f37..9c025f58aa2 100644 --- a/tools/marvin/marvin/sandbox/advanced/setup.properties +++ b/tools/marvin/marvin/sandbox/advanced/setup.properties @@ -1,4 +1,5 @@ [globals] +#global settings in cloudstack expunge.delay=60 expunge.interval=60 storage.cleanup.interval=300 @@ -17,20 +18,27 @@ secstorage.allowed.internal.sites=10.147.28.0/24 [environment] dns=10.147.28.6 mshost=10.147.29.111 -database=10.147.29.111 +mysql.host=10.147.29.111 +mysql.cloud.user=cloud +mysql.cloud.passwd=cloud [cloudstack] +#guest VLAN zone.vlan=675-679 -#pod configuration +#management network private.gateway=10.147.29.1 private.pod.startip=10.147.29.150 private.pod.endip=10.147.29.159 -#public vlan range +private.netmask=255.255.255.0 +#public network public.gateway=10.147.31.1 public.vlan=31 public.vlan.startip=10.147.31.150 public.vlan.endip=10.147.31.159 -#hosts +public.netmask=255.255.255.0 +#hypervisor host information +hypervisor=XenServer host=10.147.29.58 -#pools -pool=nfs://10.147.28.6:/export/home/sandbox/kamakura -secondary=nfs://10.147.28.6:/export/home/sandbox/sstor +host.password=password +#storage pools +primary.pool=nfs://10.147.28.6:/export/home/sandbox/kamakura +secondary.pool=nfs://10.147.28.6:/export/home/sandbox/sstor diff --git a/tools/marvin/marvin/sandbox/basic/basic_env.py b/tools/marvin/marvin/sandbox/basic/basic_env.py index e69de29bb2d..6274a2b988e 100644 --- a/tools/marvin/marvin/sandbox/basic/basic_env.py +++ b/tools/marvin/marvin/sandbox/basic/basic_env.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +''' +############################################################ +# Experimental state of scripts +# * Need to be reviewed +# * Only a sandbox +############################################################ +''' +import random +import marvin +from ConfigParser import SafeConfigParser +from optparse import OptionParser +from marvin.configGenerator import * + + +def getGlobalSettings(config): + for k, v in dict(config.items('globals')).iteritems(): + cfg = configuration() + cfg.name = k + cfg.value = v + yield cfg + + +def describeResources(config): + zs = cloudstackConfiguration() + + z = zone() + z.dns1 = config.get('environment', 'dns') + z.internaldns1 = config.get('environment', 'dns') + z.name = 'Sandbox-%s'%(config.get('cloudstack', 'hypervisor')) + z.networktype = 'Basic' + z.securitygroupenabled = 'true' + + p = pod() + p.name = 'POD0' + p.gateway = config.get('cloudstack', 'private.gateway') + p.startip = config.get('cloudstack', 'private.pod.startip') + p.endip = config.get('cloudstack', 'private.pod.endip') + p.netmask = config.get('cloudstack', 'private.netmask') + + v = iprange() + v.gateway = config.get('cloudstack', 'public.gateway') + v.startip = config.get('cloudstack', 'public.vlan.startip') + v.endip = config.get('cloudstack', 'public.vlan.endip') + v.netmask = config.get('cloudstack', 'public.netmask') + p.guestIpRanges.append(v) + + c = cluster() + c.clustername = 'C0' + c.hypervisor = config.get('cloudstack', 'hypervisor') + c.clustertype = 'CloudManaged' + + h = host() + h.username = 'root' + h.password = config.get('cloudstack', 'host.password') + h.url = 'http://%s'%(config.get('cloudstack', 'host')) + c.hosts.append(h) + + ps = primaryStorage() + ps.name = 'PS0' + ps.url = config.get('cloudstack', 'primary.pool') + c.primaryStorages.append(ps) + + p.clusters.append(c) + z.pods.append(p) + + secondary = secondaryStorage() + secondary.url = config.get('cloudstack', 'secondary.pool') + z.secondaryStorages.append(secondary) + + '''Add zone''' + zs.zones.append(z) + + '''Add mgt server''' + mgt = managementServer() + mgt.mgtSvrIp = config.get('environment', 'mshost') + zs.mgtSvr.append(mgt) + + '''Add a database''' + db = dbServer() + db.dbSvr = config.get('environment', 'mysql.host') + db.user = config.get('environment', 'mysql.cloud.user') + db.passwd = config.get('environment', 'mysql.cloud.passwd') + zs.dbSvr = db + + '''Add some configuration''' + [zs.globalConfig.append(cfg) for cfg in getGlobalSettings(config)] + + ''''add loggers''' + testClientLogger = logger() + testClientLogger.name = 'TestClient' + testClientLogger.file = '/var/log/testclient.log' + + testCaseLogger = logger() + testCaseLogger.name = 'TestCase' + testCaseLogger.file = '/var/log/testcase.log' + + zs.logger.append(testClientLogger) + zs.logger.append(testCaseLogger) + return zs + + +if __name__ == '__main__': + parser = OptionParser() + parser.add_option('-i', '--input', action='store', default='setup.properties', \ + dest='input', help='file containing environment setup information') + parser.add_option('-o', '--output', action='store', default='./sandbox.cfg', \ + dest='output', help='path where environment json will be generated') + + + (opts, args) = parser.parse_args() + + cfg_parser = SafeConfigParser() + cfg_parser.read(opts.input) + + cfg = describeResources(cfg_parser) + generate_setup_config(cfg, opts.output) diff --git a/tools/marvin/setup.py b/tools/marvin/setup.py index 83c9c8a0a32..af40771d6a4 100644 --- a/tools/marvin/setup.py +++ b/tools/marvin/setup.py @@ -20,7 +20,7 @@ setup(name="Marvin", long_description="Marvin is the cloudstack testclient written around the python unittest framework", platforms=("Any",), url="http://jenkins.cloudstack.org:8080/job/marvin", - packages=["marvin", "marvin.cloudstackAPI", "marvin.sandbox", "marvin.pymysql", "marvin.pymysql.constants", "marvin.pymysql.tests"], + packages=["marvin", "marvin.cloudstackAPI", "marvin.sandbox", "marvin.sandbox.advanced", "marvin.sandbox.basic", "marvin.pymysql", "marvin.pymysql.constants", "marvin.pymysql.tests"], license="LICENSE.txt", install_requires=[ "Python>=2.7",