diff options
author | Morgan Richomme <morgan.richomme@orange.com> | 2017-03-01 08:55:31 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-03-01 08:55:31 +0000 |
commit | f700b4d0d2c04d391c505db91b55f857b3088def (patch) | |
tree | c144dc4659ed7840efd0b5ec15432c0fac4b2b7f /functest/tests/unit/utils/test_openstack_utils.py | |
parent | e860b00fd6481130e25c29885b8c6b59ee71b30d (diff) | |
parent | f8c0ae3d732cb423902c1de5caec262a98b044b6 (diff) |
Merge "[odl-sfc] Add function to retrieve a resource from HEAT"
Diffstat (limited to 'functest/tests/unit/utils/test_openstack_utils.py')
-rw-r--r-- | functest/tests/unit/utils/test_openstack_utils.py | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py index 447271fc..ef3764cc 100644 --- a/functest/tests/unit/utils/test_openstack_utils.py +++ b/functest/tests/unit/utils/test_openstack_utils.py @@ -104,7 +104,6 @@ class OSUtilsTesting(unittest.TestCase): 'servers.create.return_value': self.instance, 'flavors.list.return_value': [self.flavor], 'flavors.find.return_value': self.flavor, - 'flavors.list.return_value': [self.flavor], 'servers.add_floating_ip.return_value': mock.Mock(), 'servers.force_delete.return_value': mock.Mock(), 'aggregates.list.return_value': [self.aggregate], @@ -162,6 +161,15 @@ class OSUtilsTesting(unittest.TestCase): } self.cinder_client.configure_mock(**attrs) + self.resource = mock.Mock() + attrs = {'id': 'resource_test_id', + 'name': 'resource_test_name' + } + + self.heat_client = mock.Mock() + attrs = {'resources.get.return_value': self.resource} + self.heat_client.configure_mock(**attrs) + mock_obj = mock.Mock() attrs = {'id': 'tenant_id', 'name': 'test_tenant'} @@ -543,6 +551,36 @@ class OSUtilsTesting(unittest.TestCase): mock_glan_client.assert_called_once_with('3', session=mock_session_obj) + @mock.patch('functest.utils.openstack_utils.os.getenv', + return_value=None) + def test_get_heat_client_version_missing_env(self, mock_os_getenv): + self.assertEqual(openstack_utils.get_heat_client_version(), + openstack_utils.DEFAULT_HEAT_API_VERSION) + + @mock.patch('functest.utils.openstack_utils.logger.info') + @mock.patch('functest.utils.openstack_utils.os.getenv', return_value='1') + def test_get_heat_client_version_default(self, mock_os_getenv, + mock_logger_info): + self.assertEqual(openstack_utils.get_heat_client_version(), '1') + mock_logger_info.assert_called_once_with( + "OS_ORCHESTRATION_API_VERSION is set in env as '%s'", '1') + + def test_get_heat_client(self): + mock_heat_obj = mock.Mock() + mock_session_obj = mock.Mock() + with mock.patch('functest.utils.openstack_utils' + '.get_heat_client_version', return_value='1'), \ + mock.patch('functest.utils.openstack_utils' + '.heatclient.Client', + return_value=mock_heat_obj) \ + as mock_heat_client, \ + mock.patch('functest.utils.openstack_utils.get_session', + return_value=mock_session_obj): + self.assertEqual(openstack_utils.get_heat_client(), + mock_heat_obj) + mock_heat_client.assert_called_once_with('1', + session=mock_session_obj) + def test_get_instances_default(self): self.assertEqual(openstack_utils.get_instances(self.nova_client), [self.instance]) @@ -1700,6 +1738,24 @@ class OSUtilsTesting(unittest.TestCase): 'user_id')) self.assertTrue(mock_logger_error.called) + def test_get_resource_default(self): + with mock.patch('functest.utils.openstack_utils.' + 'is_keystone_v3', return_value=True): + self.assertEqual(openstack_utils. + get_resource(self.heat_client, + 'stack_id', + 'resource'), + self.resource) + + @mock.patch('functest.utils.openstack_utils.logger.error') + def test_get_resource_exception(self, mock_logger_error): + self.assertEqual(openstack_utils. + get_resource(Exception, + 'stack_id', + 'resource'), + None) + self.assertTrue(mock_logger_error.called) + if __name__ == "__main__": unittest.main(verbosity=2) |