Skip to content

Commit

Permalink
Analytics resource class changes
Browse files Browse the repository at this point in the history
Currently, setup_common_objects method in BaseResource class also creates the resources not required by the sanity test cases.
To solve this issue, a new class BaseSanityResource with its own setup_common_objects method having minimum resources should be inherited by BaseResource class.
With this change, setup_common_objects method of BaseSanityResource class gets called during sanity run, eliminating the need of creating an instance of BaseResource class.

Change-Id: Ib155776927a1d286b80a1eb640165e0823a280b1
Closes-bug: #1723234
  • Loading branch information
Ankitja committed Oct 25, 2017
1 parent 6680a7d commit 8aacd51
Show file tree
Hide file tree
Showing 2 changed files with 285 additions and 238 deletions.
124 changes: 75 additions & 49 deletions serial_scripts/analytics/base.py
Expand Up @@ -163,59 +163,34 @@ def createResource(id):
return ResourceFactory.factories[id].create()
createResource = staticmethod(createResource)


class BaseResource(fixtures.Fixture):
class BaseSanityResource(fixtures.Fixture):

__metaclass__ = Singleton

def setUp(self,inputs,connections):
super(BaseResource , self).setUp()
super(BaseSanityResource , self).setUp()
self.inputs = inputs
self.connections = connections
self.setup_common_objects(self.inputs , self.connections)
self.setup_sanity_common_objects(self.inputs , self.connections)

def cleanUp(self):
super(BaseResource, self).cleanUp()

def setup_common_objects(self, inputs , connections):

self.inputs = inputs
super(BaseSanityResource, self).cleanUp()

#self.inputs.set_af('dual')
def setup_sanity_common_objects(self, inputs , connections):
self.inputs = inputs
self.connections = connections
self.orch = self.connections.orch
self.logger = self.inputs.logger
#(self.vn1_name, self.vn1_subnets)= ("vn1", ["192.168.1.0/24"])
#(self.vn2_name, self.vn2_subnets)= ("vn2", ["192.168.2.0/24"])
#(self.fip_vn_name, self.fip_vn_subnets)= ("fip_vn", ['100.1.1.0/24'])
(self.vn1_name, self.vn2_name, self.fip_vn_name)= (get_random_name("vn1"), \
get_random_name("vn2"),get_random_name("fip_vn"))
(self.vn1_vm1_name, self.vn1_vm2_name)=( get_random_name('vn1_vm1'), get_random_name('vn1_vm2'))
self.vn2_vm1_name= get_random_name('vn2_vm1')
self.vn2_vm2_name= get_random_name('vn2_vm2')
self.fvn_vm1_name= get_random_name('fvn_vm1')

# Configure 3 VNs, one of them being Floating-VN
self.vn1_name = get_random_name("vn1")
(self.vn1_vm1_name, self.vn1_vm2_name) = (get_random_name('vn1_vm1'),
get_random_name('vn1_vm2'))

self.vn1_fixture=self.useFixture( VNFixture(project_name= self.inputs.project_name,
connections= self.connections, inputs= self.inputs,
vn_name= self.vn1_name))

self.vn2_fixture=self.useFixture( VNFixture(project_name= self.inputs.project_name,
connections= self.connections, inputs= self.inputs,
vn_name= self.vn2_name))

self.fvn_fixture=self.useFixture( VNFixture(project_name= self.inputs.project_name,
connections= self.connections, inputs= self.inputs,
vn_name= self.fip_vn_name))

# Making sure VM falls on diffrent compute host
host_list = self.orch.get_hosts()
compute_1 = host_list[0]
compute_2 = host_list[0]
if len(host_list) > 1:
compute_1 = host_list[0]
compute_2 = host_list[1]
# Configure 6 VMs in VN1, 1 VM in VN2, and 1 VM in FVN
self.vn1_vm1_fixture=self.useFixture(VMFixture(project_name= self.inputs.project_name,
connections= self.connections, vn_obj= self.vn1_fixture.obj,
vm_name= self.vn1_vm1_name,image_name='ubuntu-traffic',
Expand All @@ -226,32 +201,73 @@ def setup_common_objects(self, inputs , connections):
vm_name= self.vn1_vm2_name , image_name='ubuntu-traffic',
flavor='contrail_flavor_medium'))

self.verify_sanity_common_objects()
#end setup_common_objects

def verify_sanity_common_objects(self):
assert self.vn1_fixture.verify_on_setup()
assert self.vn1_vm1_fixture.wait_till_vm_is_up()
assert self.vn1_vm2_fixture.wait_till_vm_is_up()
#end verify_common_objects


class BaseResource(BaseSanityResource):

__metaclass__ = Singleton

def setUp(self,inputs,connections):
super(BaseResource , self).setUp(inputs, connections)
self.setup_common_objects(self.inputs , self.connections)

def cleanUp(self):
super(BaseResource, self).cleanUp()

def setup_common_objects(self, inputs , connections):
(self.vn2_name, self.fip_vn_name) = (get_random_name("vn2"), get_random_name("fip_vn"))
self.vn2_vm2_name = get_random_name('vn2_vm2')
self.fvn_vm1_name = get_random_name('fvn_vm1')

self.vn2_fixture = self.useFixture(VNFixture(
project_name=self.inputs.project_name,
connections=self.connections,
inputs=self.inputs,
vn_name=self.vn2_name))

self.fvn_fixture = self.useFixture(VNFixture(
project_name=self.inputs.project_name,
connections=self.connections,
inputs=self.inputs,
vn_name=self.fip_vn_name))

# Making sure VM falls on diffrent compute host
self.orch = self.connections.orch
host_list = self.orch.get_hosts()
compute_2 = host_list[0]
if len(host_list) > 1:
compute_2 = host_list[1]

self.vn2_vm2_fixture=self.useFixture(VMFixture(project_name= self.inputs.project_name,
connections= self.connections, vn_obj= self.vn2_fixture.obj,
vm_name= self.vn2_vm2_name, image_name='ubuntu-traffic', flavor='contrail_flavor_medium',
vm_name= self.vn2_vm2_name, image_name='ubuntu-traffic',
node_name=compute_2))
#
self.fvn_vm1_fixture=self.useFixture(VMFixture(project_name= self.inputs.project_name,
connections= self.connections, vn_obj= self.fvn_fixture.obj,
vm_name= self.fvn_vm1_name))

self.multi_intf_vm_fixture = self.useFixture(VMFixture(connections=self.connections,
vn_objs=[self.vn1_fixture.obj , self.vn2_fixture.obj],
vm_name='mltf_vm',
project_name=self.inputs.project_name))

self.verify_common_objects()
#end setup_common_objects

def verify_common_objects(self):
assert self.vn1_fixture.verify_on_setup()
super(BaseResource , self).verify_sanity_common_objects()
assert self.vn2_fixture.verify_on_setup()
assert self.fvn_fixture.verify_on_setup()
assert self.vn1_vm1_fixture.verify_on_setup()
assert self.vn1_vm2_fixture.verify_on_setup()
assert self.fvn_vm1_fixture.verify_on_setup()
assert self.vn2_vm2_fixture.verify_on_setup()
assert self.multi_intf_vm_fixture.verify_on_setup()
assert self.fvn_vm1_fixture.wait_till_vm_is_up()
assert self.vn2_vm2_fixture.wait_till_vm_is_up()
assert self.multi_intf_vm_fixture.wait_till_vm_is_up()
#end verify_common_objects

def start_traffic(self):
Expand Down Expand Up @@ -312,8 +328,18 @@ def stop_traffic(self):
self.logger.info("Sent traffic: %s"%(self.sender.sent))
self.logger.info("Received traffic: %s"%(self.receiver.recv))

class AnalyticsTestSanityWithMinResource(BaseSanityResource):

def setUp(self,inputs,connections):
super(AnalyticsTestSanityWithMinResource , self).setUp(inputs,connections)

def cleanUp(self):
super(AnalyticsTestSanityWithMinResource , self).cleanUp()

class Factory:
def create(self): return AnalyticsTestSanityWithMinResource()

class AnalyticsTestSanityResource (BaseResource):
class AnalyticsTestSanityResource(BaseResource):

def setUp(self,inputs,connections):
pass
Expand All @@ -326,7 +352,7 @@ def cleanUp(self):
class Factory:
def create(self): return AnalyticsTestSanityResource()

class AnalyticsTestSanity1Resource (BaseResource):
class AnalyticsTestSanity1Resource(BaseResource):

def setUp(self,inputs,connections):
pass
Expand All @@ -340,7 +366,7 @@ class Factory:
def create(self): return AnalyticsTestSanity1Resource()


class AnalyticsTestSanity2Resource (BaseResource):
class AnalyticsTestSanity2Resource(BaseResource):

def setUp(self,inputs,connections):
pass
Expand All @@ -353,7 +379,7 @@ def cleanUp(self):
class Factory:
def create(self): return AnalyticsTestSanity2Resource()

class AnalyticsTestSanity3Resource (BaseResource):
class AnalyticsTestSanity3Resource(BaseResource):

def setUp(self,inputs,connections):
pass
Expand Down

0 comments on commit 8aacd51

Please sign in to comment.