Merge "More javelin unit tests"
diff --git a/tempest/tests/cmd/test_javelin.py b/tempest/tests/cmd/test_javelin.py
index e1ca829..f0921d5 100644
--- a/tempest/tests/cmd/test_javelin.py
+++ b/tempest/tests/cmd/test_javelin.py
@@ -245,14 +245,49 @@
mocked_function = self.fake_client.volumes.wait_for_volume_status
self.assertFalse(mocked_function.called)
+ def test_create_router(self):
+
+ self.fake_client.networks.list_routers.return_value = {'routers': []}
+ self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
+ return_value=self.fake_client))
+
+ javelin.create_routers([self.fake_object])
+
+ mocked_function = self.fake_client.networks.create_router
+ mocked_function.assert_called_once_with(self.fake_object['name'])
+
+ def test_create_router_existing(self):
+ self.fake_client.networks.list_routers.return_value = {
+ 'routers': [self.fake_object]}
+ self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
+ return_value=self.fake_client))
+
+ javelin.create_routers([self.fake_object])
+
+ mocked_function = self.fake_client.networks.create_router
+ self.assertFalse(mocked_function.called)
+
+ def test_create_secgroup(self):
+ self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
+ return_value=self.fake_client))
+ self.fake_client.secgroups.list_security_groups.return_value = []
+ self.fake_client.secgroups.create_security_group.return_value = \
+ {'id': self.fake_object['secgroup_id']}
+
+ javelin.create_secgroups([self.fake_object])
+
+ mocked_function = self.fake_client.secgroups.create_security_group
+ mocked_function.assert_called_once_with(
+ self.fake_object['name'],
+ self.fake_object['description'])
+
class TestDestroyResources(JavelinUnitTest):
def test_destroy_tenants(self):
fake_tenant = self.fake_object['tenant']
-
- fake_auth = mock.MagicMock()
+ fake_auth = self.fake_client
fake_auth.identity.get_tenant_by_name.return_value = fake_tenant
self.useFixture(mockpatch.PatchObject(javelin, "keystone_admin",
@@ -267,7 +302,7 @@
fake_user = self.fake_object['user']
fake_tenant = self.fake_object['tenant']
- fake_auth = mock.MagicMock()
+ fake_auth = self.fake_client
fake_auth.identity.get_tenant_by_name.return_value = fake_tenant
fake_auth.identity.get_user_by_username.return_value = fake_user
@@ -281,42 +316,40 @@
def test_destroy_objects(self):
- fake_client = mock.MagicMock()
- fake_client.objects.delete_object.return_value = {'status': "200"}, ""
+ self.fake_client.objects.delete_object.return_value = \
+ {'status': "200"}, ""
self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
- return_value=fake_client))
+ return_value=self.fake_client))
javelin.destroy_objects([self.fake_object])
- mocked_function = fake_client.objects.delete_object
+ mocked_function = self.fake_client.objects.delete_object
mocked_function.asswert_called_once(self.fake_object['container'],
self.fake_object['name'])
def test_destroy_images(self):
- fake_client = mock.MagicMock()
self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
- return_value=fake_client))
+ return_value=self.fake_client))
self.useFixture(mockpatch.PatchObject(javelin, "_get_image_by_name",
return_value=self.fake_object['image']))
javelin.destroy_images([self.fake_object])
- mocked_function = fake_client.images.delete_image
+ mocked_function = self.fake_client.images.delete_image
mocked_function.assert_called_once_with(
self.fake_object['image']['id'])
def test_destroy_networks(self):
- fake_client = mock.MagicMock()
self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
- return_value=fake_client))
+ return_value=self.fake_client))
self.useFixture(mockpatch.PatchObject(
javelin, "_get_resource_by_name",
return_value=self.fake_object['resource']))
javelin.destroy_networks([self.fake_object])
- mocked_function = fake_client.networks.delete_network
+ mocked_function = self.fake_client.networks.delete_network
mocked_function.assert_called_once_with(
self.fake_object['resource']['id'])
@@ -334,3 +367,47 @@
mocked_function.assert_called_once_with(self.fake_object.volume['id'])
mocked_function = self.fake_client.volumes.delete_volume
mocked_function.assert_called_once_with(self.fake_object.volume['id'])
+
+ def test_destroy_subnets(self):
+
+ self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
+ return_value=self.fake_client))
+ fake_subnet_id = self.fake_object['subnet_id']
+ self.useFixture(mockpatch.PatchObject(javelin, "_get_resource_by_name",
+ return_value={
+ 'id': fake_subnet_id}))
+
+ javelin.destroy_subnets([self.fake_object])
+
+ mocked_function = self.fake_client.networks.delete_subnet
+ mocked_function.assert_called_once_with(fake_subnet_id)
+
+ def test_destroy_routers(self):
+ self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
+ return_value=self.fake_client))
+
+ # this function is used on 2 different occasions in the code
+ def _fake_get_resource_by_name(*args):
+ if args[1] == "routers":
+ return {"id": self.fake_object['router_id']}
+ elif args[1] == "subnets":
+ return {"id": self.fake_object['subnet_id']}
+ javelin._get_resource_by_name = _fake_get_resource_by_name
+
+ javelin.destroy_routers([self.fake_object])
+
+ mocked_function = self.fake_client.networks.delete_router
+ mocked_function.assert_called_once_with(
+ self.fake_object['router_id'])
+
+ def test_destroy_secgroup(self):
+ self.useFixture(mockpatch.PatchObject(javelin, "client_for_user",
+ return_value=self.fake_client))
+ fake_secgroup = {'id': self.fake_object['id']}
+ self.useFixture(mockpatch.PatchObject(javelin, "_get_resource_by_name",
+ return_value=fake_secgroup))
+
+ javelin.destroy_secgroups([self.fake_object])
+
+ mocked_function = self.fake_client.secgroups.delete_security_group
+ mocked_function.assert_called_once_with(self.fake_object['id'])