Skip to content

Commit

Permalink
Merge "Adding testcase for 1590971"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Aug 5, 2016
2 parents 03c8104 + 334cee9 commit cdef9f4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
38 changes: 35 additions & 3 deletions 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):

Expand Down Expand Up @@ -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__

Expand All @@ -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']

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion fixtures/quantum_test.py
Expand Up @@ -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,
}
Expand All @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions tcutils/config/vnc_api_results.py
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions tcutils/config/vnc_introspect_utils.py
Expand Up @@ -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()
Expand Down

0 comments on commit cdef9f4

Please sign in to comment.