Fix py27/py35 errors on jenkins gate

This patch fixeds the failing test cases to assert the dict objects
of expected and actual templates in test case outputs instead of yaml
string comparison as yaml strings does not guarantee the order of
generated heat templates.

Change-Id: I7e1ff9079328c62e4f56783481b3ca685cb90edf
Closes-Bug: #1627410
This commit is contained in:
Sripriya 2016-09-24 19:03:45 -07:00
parent d3a2fbc861
commit 35a87d1ce8
5 changed files with 112 additions and 84 deletions

View File

@ -25,12 +25,14 @@ def _get_template(name):
f = codecs.open(filename, encoding='utf-8', errors='strict')
return f.read()
vnfd_openwrt = _get_template('test_tosca_openwrt.yaml')
vnfd_openwrt = _get_template('openwrt.yaml')
tosca_vnfd_openwrt = _get_template('test_tosca_openwrt.yaml')
vnfd_ipparams_template = _get_template('vnf_cirros_template_ipaddr.yaml')
ipparams = _get_template('vnf_cirros_param_values_ipaddr.yaml')
vnfd_userdata_template = _get_template('vnf_cirros_template_user_data.yaml')
userdata_params = _get_template('vnf_cirros_param_values_user_data.yaml')
config_data = _get_template('config_data.yaml')
update_config_data = _get_template('update_config_data.yaml')
vnffgd_template = yaml.load(_get_template('vnffgd_template.yaml'))
vnffgd_tosca_template = yaml.load(_get_template('tosca_vnffgd_template.yaml'))
vnffgd_invalid_tosca_template = yaml.load(_get_template(
@ -43,7 +45,8 @@ def get_dummy_vnfd_obj():
'name': 'dummy_vnfd',
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
u'mgmt_driver': u'noop',
u'attributes': {u'vnfd': yaml.safe_load(vnfd_openwrt)},
u'attributes': {u'vnfd': yaml.safe_load(
tosca_vnfd_openwrt)},
'description': 'dummy_vnfd_description'},
u'auth': {u'tenantName': u'admin', u'passwordCredentials': {
u'username': u'admin', u'password': u'devstack'}}}
@ -82,7 +85,7 @@ def get_dummy_device_obj():
'description': u'OpenWRT with services'}
def get_dummy_device_obj_config_attr():
def get_dummy_vnf_config_attr():
return {'status': 'PENDING_CREATE', 'instance_id': None, 'name':
u'test_openwrt', 'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
'vnfd_id': u'eb094833-995e-49f0-a047-dfb56aaf7c4e',
@ -91,7 +94,7 @@ def get_dummy_device_obj_config_attr():
'description': u'OpenWRT with services',
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
'mgmt_driver': u'openwrt',
'attributes': {u'vnfd': vnfd_openwrt},
'attributes': {u'vnfd': tosca_vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
u'openwrt_services'}, 'mgmt_url': None, 'service_context': [],
'attributes': {u'config': config_data},
@ -99,18 +102,8 @@ def get_dummy_device_obj_config_attr():
'description': u'OpenWRT with services'}
def get_dummy_device_update_config_attr():
return {'vnf': {u'attributes': {u'config': u"vdus:\n vdu1:\n "
u"config:\n firewall: |"
u"\n package firewall"
u"\n\n config default"
u"s\n "
u"option syn_flood '10'\n "
u" option input "
u"'REJECT'\n "
u"option output 'REJECT'\n "
u" option "
u"forward 'REJECT'\n"}}}
def get_dummy_vnf_update_config():
return {'vnf': {'attributes': {'config': update_config_data}}}
def get_dummy_device_obj_ipaddr_attr():

View File

@ -48,10 +48,10 @@ def _get_template(name):
class TestDeviceHeat(base.TestCase):
hot_template = _get_template('hot_tosca_openwrt.yaml')
hot_template = _get_template('hot_openwrt.yaml')
hot_param_template = _get_template('hot_openwrt_params.yaml')
hot_ipparam_template = _get_template('hot_openwrt_ipparams.yaml')
vnfd_openwrt = _get_template('test_tosca_openwrt.yaml')
tosca_vnfd_openwrt = _get_template('test_tosca_openwrt.yaml')
config_data = _get_template('config_data.yaml')
def setUp(self):
@ -77,10 +77,13 @@ class TestDeviceHeat(base.TestCase):
return {'vnfd': {'attributes': {'vnfd': template}}}
def _get_expected_vnfd(self, template):
return {'vnfd': {'attributes': {'vnfd': template},
'description': 'OpenWRT with services',
'mgmt_driver': 'openwrt',
'name': 'OpenWRT'}}
return {'attributes': {'vnfd': template},
'description': 'OpenWRT with services',
'mgmt_driver': 'openwrt', 'name': 'OpenWRT',
'service_types': [{'service_type': 'vnfd',
'id': '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}],
'tenant_id': 'ad7ebc56538745a08ef7c5e97f8bd437',
'id': 'fb048660-dc1b-4f0f-bd89-b023666650ec'}
def _get_expected_fields(self):
return {'stack_name':
@ -113,9 +116,9 @@ class TestDeviceHeat(base.TestCase):
'description': u'OpenWRT with services',
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
'mgmt_driver': u'openwrt',
'attributes': {u'vnfd': self.vnfd_openwrt},
'attributes': {u'vnfd': self.tosca_vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec',
'name': u'openwrt_services'},
'name': u'OpenWRT'},
'mgmt_url': '{"vdu1": "192.168.120.31"}',
'service_context': [],
'attributes': {u'param_values': param_values},
@ -131,16 +134,10 @@ class TestDeviceHeat(base.TestCase):
u'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}], 'description':
u'OpenWRT with services', 'tenant_id':
u'ad7ebc56538745a08ef7c5e97f8bd437', 'mgmt_driver': u'openwrt',
'attributes': {u'vnfd': self.vnfd_openwrt},
'attributes': {u'vnfd': self.tosca_vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
u'openwrt_services'}, 'mgmt_url': None, 'service_context': [],
'attributes': {u'config': 'vdus:\n vdu1:\n config: {firewall: '
'"package firewall\\n\\nconfig defaults'
'\\n option syn_flood\\\n '
'\\ \'10\'\\n option input '
'\'REJECT\'\\n option output '
'\'REJECT\'\\n \\\n \\ '
'option forward \'REJECT\'\\n"}\n'},
'attributes': {'config': utils.update_config_data},
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123', 'description':
u'OpenWRT with services'}
@ -158,7 +155,7 @@ class TestDeviceHeat(base.TestCase):
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
'mgmt_driver': u'openwrt',
'infra_driver': u'heat',
'attributes': {u'vnfd': self.vnfd_openwrt},
'attributes': {u'vnfd': self.tosca_vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec',
'name': u'openwrt_services'},
'mgmt_url': '{"vdu1": "192.168.120.31"}',
@ -166,6 +163,16 @@ class TestDeviceHeat(base.TestCase):
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
'description': u'OpenWRT with services'}
def _assert_create_result_old_template(self, expected_fields,
actual_fields, expected_result,
result):
actual_fields["template"] = yaml.safe_load(actual_fields["template"])
expected_fields["template"] = \
yaml.safe_load(expected_fields["template"])
self.assertEqual(expected_fields, actual_fields)
self.heat_client.create.assert_called_once_with(expected_fields)
self.assertEqual(expected_result, result)
def test_create(self):
vnf_obj = utils.get_dummy_device_obj()
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
@ -173,8 +180,9 @@ class TestDeviceHeat(base.TestCase):
result = self.heat_driver.create(plugin=None, context=self.context,
vnf=vnf_obj,
auth_attr=utils.get_vim_auth_obj())
self.heat_client.create.assert_called_once_with(expected_fields)
self.assertEqual(expected_result, result)
actual_fields = self.heat_client.create.call_args[0][0]
self._assert_create_result_old_template(expected_fields, actual_fields,
expected_result, result)
def test_create_user_data_param_attr(self):
vnf_obj = utils.get_dummy_device_obj_userdata_attr()
@ -183,8 +191,9 @@ class TestDeviceHeat(base.TestCase):
result = self.heat_driver.create(plugin=None, context=self.context,
vnf=vnf_obj,
auth_attr=utils.get_vim_auth_obj())
self.heat_client.create.assert_called_once_with(expected_fields)
self.assertEqual(expected_result, result)
actual_fields = self.heat_client.create.call_args[0][0]
self._assert_create_result_old_template(expected_fields, actual_fields,
expected_result, result)
def test_create_ip_addr_param_attr(self):
vnf_obj = utils.get_dummy_device_obj_ipaddr_attr()
@ -193,11 +202,12 @@ class TestDeviceHeat(base.TestCase):
result = self.heat_driver.create(plugin=None, context=self.context,
vnf=vnf_obj,
auth_attr=utils.get_vim_auth_obj())
self.heat_client.create.assert_called_once_with(expected_fields)
self.assertEqual(expected_result, result)
actual_fields = self.heat_client.create.call_args[0][0]
self._assert_create_result_old_template(expected_fields, actual_fields,
expected_result, result)
def test_create_wait(self):
vnf_obj = utils.get_dummy_device_obj()
vnf_obj = self._get_dummy_tosca_vnf('test_tosca_openwrt.yaml')
expected_result = self._get_expected_vnf_wait_obj()
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
self.heat_driver.create_wait(plugin=None,
@ -215,14 +225,18 @@ class TestDeviceHeat(base.TestCase):
self.heat_client.delete.assert_called_once_with(vnf_id)
def test_update(self):
vnf_obj = utils.get_dummy_device_obj_config_attr()
vnf_config_obj = utils.get_dummy_device_update_config_attr()
vnf_obj = utils.get_dummy_vnf_config_attr()
vnf_config_obj = utils.get_dummy_vnf_update_config()
expected_vnf_update = self._get_expected_vnf_update_obj()
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
self.heat_driver.update(plugin=None, context=self.context,
vnf_id=vnf_id, vnf_dict=vnf_obj,
vnf=vnf_config_obj,
auth_attr=utils.get_vim_auth_obj())
expected_vnf_update['attributes']['config'] = yaml.load(
expected_vnf_update['attributes']['config'])
vnf_obj['attributes']['config'] = yaml.load(vnf_obj['attributes'][
'config'])
self.assertEqual(expected_vnf_update, vnf_obj)
def _get_expected_fields_tosca(self, template):
@ -242,7 +256,7 @@ class TestDeviceHeat(base.TestCase):
exp_tmpl = self._get_expected_vnfd(tosca_tpl)
tosca_hw_dict = yaml.safe_load(_get_template(hot_tpl_name))
dvc = {
'vnfd': exp_tmpl['vnfd'],
'vnfd': exp_tmpl,
'description': u'OpenWRT with services',
'attributes': {
'heat_template': tosca_hw_dict,
@ -274,10 +288,8 @@ class TestDeviceHeat(base.TestCase):
tosca_template = _get_template(template)
vnf = utils.get_dummy_device_obj()
dtemplate = self._get_expected_vnfd(tosca_template)
dtemplate['service_types'] = [{'service_type': 'vnfd', 'id':
'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}]
dtemplate['tenant_id'] = 'ad7ebc56538745a08ef7c5e97f8bd437'
vnf['vnfd'] = dtemplate['vnfd']
vnf['vnfd'] = dtemplate
vnf['attributes'] = {}
vnf['attributes']['param_values'] = input_params
if is_alarm:

View File

@ -0,0 +1,11 @@
vdus:
vdu1:
config:
firewall: |
package firewall
config defaults
option syn_flood '3'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'ACCEPT'

View File

@ -48,10 +48,10 @@ def _get_template(name):
class TestOpenStack(base.TestCase):
hot_template = _get_template('hot_tosca_openwrt.yaml')
hot_template = _get_template('hot_openwrt.yaml')
hot_param_template = _get_template('hot_openwrt_params.yaml')
hot_ipparam_template = _get_template('hot_openwrt_ipparams.yaml')
vnfd_openwrt = _get_template('test_tosca_openwrt.yaml')
tosca_vnfd_openwrt = _get_template('test_tosca_openwrt.yaml')
config_data = _get_template('config_data.yaml')
def setUp(self):
@ -77,10 +77,13 @@ class TestOpenStack(base.TestCase):
return {'vnfd': {'attributes': {'vnfd': template}}}
def _get_expected_vnfd(self, template):
return {'vnfd': {'attributes': {'vnfd': template},
'description': 'OpenWRT with services',
'mgmt_driver': 'openwrt',
'name': 'OpenWRT'}}
return {'attributes': {'vnfd': template},
'description': 'OpenWRT with services',
'mgmt_driver': 'openwrt', 'name': 'OpenWRT',
'service_types': [{'service_type': 'vnfd',
'id': '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}],
'tenant_id': 'ad7ebc56538745a08ef7c5e97f8bd437',
'id': 'fb048660-dc1b-4f0f-bd89-b023666650ec'}
def _get_expected_fields(self):
return {'stack_name':
@ -113,9 +116,9 @@ class TestOpenStack(base.TestCase):
'description': u'OpenWRT with services',
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
'mgmt_driver': u'openwrt',
'attributes': {u'vnfd': self.vnfd_openwrt},
'attributes': {u'vnfd': self.tosca_vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec',
'name': u'openwrt_services'},
'name': u'OpenWRT'},
'mgmt_url': '{"vdu1": "192.168.120.31"}',
'service_context': [],
'attributes': {u'param_values': param_values},
@ -131,16 +134,10 @@ class TestOpenStack(base.TestCase):
u'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}], 'description':
u'OpenWRT with services', 'tenant_id':
u'ad7ebc56538745a08ef7c5e97f8bd437', 'mgmt_driver': u'openwrt',
'attributes': {u'vnfd': self.vnfd_openwrt},
'attributes': {u'vnfd': self.tosca_vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec', 'name':
u'openwrt_services'}, 'mgmt_url': None, 'service_context': [],
'attributes': {u'config': 'vdus:\n vdu1:\n config: {firewall: '
'"package firewall\\n\\nconfig defaults'
'\\n option syn_flood\\\n '
'\\ \'10\'\\n option input '
'\'REJECT\'\\n option output '
'\'REJECT\'\\n \\\n \\ '
'option forward \'REJECT\'\\n"}\n'},
'attributes': {'config': utils.update_config_data},
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123', 'description':
u'OpenWRT with services'}
@ -158,7 +155,7 @@ class TestOpenStack(base.TestCase):
'tenant_id': u'ad7ebc56538745a08ef7c5e97f8bd437',
'mgmt_driver': u'openwrt',
'infra_driver': u'heat',
'attributes': {u'vnfd': self.vnfd_openwrt},
'attributes': {u'vnfd': self.tosca_vnfd_openwrt},
'id': u'fb048660-dc1b-4f0f-bd89-b023666650ec',
'name': u'openwrt_services'},
'mgmt_url': '{"vdu1": "192.168.120.31"}',
@ -166,6 +163,16 @@ class TestOpenStack(base.TestCase):
'id': 'eb84260e-5ff7-4332-b032-50a14d6c1123',
'description': u'OpenWRT with services'}
def _assert_create_result_old_template(self, expected_fields,
actual_fields, expected_result,
result):
actual_fields["template"] = yaml.safe_load(actual_fields["template"])
expected_fields["template"] = \
yaml.safe_load(expected_fields["template"])
self.assertEqual(expected_fields, actual_fields)
self.heat_client.create.assert_called_once_with(expected_fields)
self.assertEqual(expected_result, result)
def test_create(self):
vnf_obj = utils.get_dummy_device_obj()
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
@ -173,18 +180,20 @@ class TestOpenStack(base.TestCase):
result = self.infra_driver.create(plugin=None, context=self.context,
vnf=vnf_obj,
auth_attr=utils.get_vim_auth_obj())
self.heat_client.create.assert_called_once_with(expected_fields)
self.assertEqual(expected_result, result)
actual_fields = self.heat_client.create.call_args[0][0]
self._assert_create_result_old_template(expected_fields, actual_fields,
expected_result, result)
def test_create_user_data_param_attr(self):
vnf_obj = utils.get_dummy_device_obj_userdata_attr()
expected_result = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
expected_fields = self._get_expected_fields_user_data()
result = self.infra_driver.create(plugin=None, context=self.context,
vnf=vnf_obj,
auth_attr=utils.get_vim_auth_obj())
self.heat_client.create.assert_called_once_with(expected_fields)
self.assertEqual(expected_result, result)
vnf=vnf_obj,
auth_attr=utils.get_vim_auth_obj())
actual_fields = self.heat_client.create.call_args[0][0]
self._assert_create_result_old_template(expected_fields, actual_fields,
expected_result, result)
def test_create_ip_addr_param_attr(self):
vnf_obj = utils.get_dummy_device_obj_ipaddr_attr()
@ -193,11 +202,12 @@ class TestOpenStack(base.TestCase):
result = self.infra_driver.create(plugin=None, context=self.context,
vnf=vnf_obj,
auth_attr=utils.get_vim_auth_obj())
self.heat_client.create.assert_called_once_with(expected_fields)
self.assertEqual(expected_result, result)
actual_fields = self.heat_client.create.call_args[0][0]
self._assert_create_result_old_template(expected_fields, actual_fields,
expected_result, result)
def test_create_wait(self):
vnf_obj = utils.get_dummy_device_obj()
vnf_obj = self._get_dummy_tosca_vnf('test_tosca_openwrt.yaml')
expected_result = self._get_expected_vnf_wait_obj()
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
self.infra_driver.create_wait(plugin=None,
@ -215,14 +225,18 @@ class TestOpenStack(base.TestCase):
self.heat_client.delete.assert_called_once_with(vnf_id)
def test_update(self):
vnf_obj = utils.get_dummy_device_obj_config_attr()
vnf_config_obj = utils.get_dummy_device_update_config_attr()
vnf_obj = utils.get_dummy_vnf_config_attr()
vnf_config_obj = utils.get_dummy_vnf_update_config()
expected_vnf_update = self._get_expected_vnf_update_obj()
vnf_id = '4a4c2d44-8a52-4895-9a75-9d1c76c3e738'
self.infra_driver.update(plugin=None, context=self.context,
vnf_id=vnf_id, vnf_dict=vnf_obj,
vnf=vnf_config_obj,
auth_attr=utils.get_vim_auth_obj())
vnf_id=vnf_id, vnf_dict=vnf_obj,
vnf=vnf_config_obj,
auth_attr=utils.get_vim_auth_obj())
expected_vnf_update['attributes']['config'] = yaml.load(
expected_vnf_update['attributes']['config'])
vnf_obj['attributes']['config'] = yaml.load(vnf_obj['attributes'][
'config'])
self.assertEqual(expected_vnf_update, vnf_obj)
def _get_expected_fields_tosca(self, template):
@ -241,7 +255,7 @@ class TestOpenStack(base.TestCase):
exp_tmpl = self._get_expected_vnfd(tosca_tpl)
tosca_hw_dict = yaml.safe_load(_get_template(hot_tpl_name))
dvc = {
'vnfd': exp_tmpl['vnfd'],
'vnfd': exp_tmpl,
'description': u'OpenWRT with services',
'attributes': {
'heat_template': tosca_hw_dict,
@ -272,10 +286,8 @@ class TestOpenStack(base.TestCase):
tosca_template = _get_template(template)
vnf = utils.get_dummy_device_obj()
dtemplate = self._get_expected_vnfd(tosca_template)
dtemplate['service_types'] = [{'service_type': 'vnfd', 'id':
'4a4c2d44-8a52-4895-9a75-9d1c76c3e738'}]
dtemplate['tenant_id'] = 'ad7ebc56538745a08ef7c5e97f8bd437'
vnf['vnfd'] = dtemplate['vnfd']
vnf['vnfd'] = dtemplate
vnf['attributes'] = {}
vnf['attributes']['param_values'] = input_params
return vnf

View File

@ -201,7 +201,7 @@ class TestVNFMPlugin(db_base.SqlTestCase):
self.assertIn('attributes', result)
self.assertIn('created_at', result)
self.assertIn('updated_at', result)
yaml_dict = yaml.safe_load(utils.vnfd_openwrt)
yaml_dict = yaml.safe_load(utils.tosca_vnfd_openwrt)
mock_tosca_template.assert_called_once_with(
a_file=False, yaml_dict_tpl=yaml_dict)
mock_get_mgmt_driver.assert_called_once_with(mock.ANY)