From 334cee9b6543319b27d02a1166cd4518e4b26bb6 Mon Sep 17 00:00:00 2001 From: Senthilnathan Murugappan Date: Mon, 25 Jul 2016 23:09:47 -0700 Subject: [PATCH] Adding testcase for 1590971 Change-Id: Id875bdc8a912cb23c9c828816b11cff740b2200d --- fixtures/port_fixture.py | 38 ++++++++++++++++++++++++-- fixtures/quantum_test.py | 5 +++- tcutils/config/vnc_api_results.py | 10 +++++++ tcutils/config/vnc_introspect_utils.py | 12 ++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/fixtures/port_fixture.py b/fixtures/port_fixture.py index bcff1edd0..606ed8509 100644 --- a/fixtures/port_fixture.py +++ b/fixtures/port_fixture.py @@ -1,4 +1,7 @@ import vnc_api_test +from tcutils.util import retry +import json +import uuid class PortFixture(vnc_api_test.VncLibFixture): @@ -36,7 +39,7 @@ def __init__(self, *args, **kwargs): self.extra_dhcp_opts = kwargs.get('extra_dhcp_opts', []) self.api_type = kwargs.get('api_type', 'neutron') self.project_obj = kwargs.get('project_obj', None) - + self.binding_profile = kwargs.get('binding_profile', None) self.vn_obj = None # end __init__ @@ -61,7 +64,8 @@ def _neutron_create_port(self): fixed_ips=self.fixed_ips, mac_address=self.mac_address, security_groups=self.security_groups, - extra_dhcp_opts=self.extra_dhcp_opts) + extra_dhcp_opts=self.extra_dhcp_opts, + binding_profile=self.binding_profile) self.neutron_obj = neutron_obj self.uuid = neutron_obj['id'] @@ -95,6 +99,13 @@ def _contrail_create_port(self): # TODO pass + if self.binding_profile: + bind_kv = vnc_api_test.KeyValuePair(key='profile', value=str(self.binding_profile)) + kv_pairs = vmi_obj.get_virtual_machine_interface_bindings() or\ + vnc_api_test.KeyValuePairs() + kv_pairs.add_key_value_pair(bind_kv) + vmi_obj.set_virtual_machine_interface_bindings(kv_pairs) + self.vmi_obj = self.vnc_api_h.virtual_machine_interface_create(vmi_obj) self.uuid = vmi_id @@ -135,8 +146,29 @@ def _contrail_delete_port(self): self.vnc_api_h.instance_ip_delete(id=vmi_iip_uuid) self.vnc_api_h.virtual_machine_interface_delete(id=self.uuid) + def verify_on_setup(self): + if not self.verify_port_in_api_server(): + self.logger.error('VMI %s verification in API Server failed'%self.uuid) + return False + else: + self.logger.info('VMI %s verification in API Server passed'%self.uuid) + return True + + @retry(delay=2, tries=5) def verify_port_in_api_server(self): - pass + api_h = self.connections.api_server_inspect + vmi = api_h.get_cs_vmi(self.uuid) + if not vmi: + self.logger.warn('Unable to fetch VMI %s from API server'%self.uuid) + return False + if self.binding_profile: + bindings = vmi.get_bindings() + if bindings['profile'] != json.dumps(self.binding_profile): + self.logger.warn('VMI binding profile doesnt match.' + 'Expected %s actual %s for VMI %s'%( + self.binding_profile, bindings['profile'], self.uuid)) + return False + return True def verify_port_in_control_node_ifmap(self): pass diff --git a/fixtures/quantum_test.py b/fixtures/quantum_test.py index aa9664bf4..a7ff35474 100644 --- a/fixtures/quantum_test.py +++ b/fixtures/quantum_test.py @@ -114,7 +114,8 @@ def create_subnet(self, subnet, net_id, ipam_fq_name=None, enable_dhcp=True, dis def create_port(self, net_id, fixed_ips=[], mac_address=None, no_security_group=False, - security_groups=[], extra_dhcp_opts=None,sriov=False): + security_groups=[], extra_dhcp_opts=None, + sriov=False, binding_profile=None): port_req_dict = { 'network_id': net_id, } @@ -131,6 +132,8 @@ def create_port(self, net_id, fixed_ips=[], port_req_dict['fixed_ips'] = fixed_ips if sriov: port_req_dict['binding:vnic_type'] = 'direct' + if binding_profile: + port_req_dict['binding:profile'] = binding_profile try: port_rsp = self.obj.create_port({'port': port_req_dict}) self.logger.debug('Response for create_port : ' + repr(port_rsp)) diff --git a/tcutils/config/vnc_api_results.py b/tcutils/config/vnc_api_results.py index 5627f384a..839077d47 100644 --- a/tcutils/config/vnc_api_results.py +++ b/tcutils/config/vnc_api_results.py @@ -491,6 +491,16 @@ def vmi_links(self): # 0, 'href') +class CsVMIResult (Result): + def get_bindings(self): + bindings = self.xpath('virtual-machine-interface', + 'virtual_machine_interface_bindings', + 'key_value_pair') + bdict = dict() + for binding in bindings: + bdict[binding['key']] = binding['value'] + return bdict + class CsVrOfVmResult (Result): def name(self): diff --git a/tcutils/config/vnc_introspect_utils.py b/tcutils/config/vnc_introspect_utils.py index ea0bc5b04..97b8b3c20 100755 --- a/tcutils/config/vnc_introspect_utils.py +++ b/tcutils/config/vnc_introspect_utils.py @@ -714,6 +714,18 @@ def get_loadbalancer(self, lb_id, refresh=True): self.update_cache('loadbalancer', p.fq_name().split(':'), p) return p + def get_cs_vmi(self, vmi_id): + ''' + method: get_loadbalancer find the loadbalancer + returns None if not found, a dict w/ attrib. eg: + + ''' + obj = self.dict_get('virtual-machine-interface/%s' %vmi_id) + if obj: + return CsVMIResult(obj) + return None + + if __name__ == '__main__': va = VNCApiInspect('10.84.7.2') r = va.get_cs_domain()