def test_setup_failexists(self, mock_clients): # Setup and mock new_context = copy.deepcopy(self.context) new_context["flavors"] = {} mock_flavor_create = mock_clients().nova().flavors.create exception = nova_exceptions.Conflict("conflict") mock_flavor_create.side_effect = exception # Run flavors_ctx = flavors.FlavorsGenerator(self.context) flavors_ctx.setup() # Assertions self.assertEqual(new_context, flavors_ctx.context) mock_clients.assert_called_with(self.context["admin"]["credential"]) mock_flavor_create.assert_called_once_with(name="flavor_name", ram=2048, vcpus=3, disk=10, ephemeral=3, swap=5)
def test_cleanup(self, mock_cleanup, mock_make_name_matcher): # Setup and mock real_context = { "config": { "flavors": [ { "name": "flavor_name" }, ] }, "admin": { "credential": mock.MagicMock() }, "task": mock.MagicMock(), } # Run flavors_ctx = flavors.FlavorsGenerator(real_context) flavors_ctx.cleanup() mock_cleanup.assert_called_once_with( names=["nova.flavors"], admin=real_context["admin"], api_versions=None, superclass=mock_make_name_matcher.return_value, task_id=flavors_ctx.get_owner_id()) mock_make_name_matcher.assert_called_once_with("flavor_name")
def test_setup(self, mock_clients): # Setup and mock mock_create = mock_clients().nova().flavors.create mock_create().to_dict.return_value = {"flavor_key": "flavor_value"} # Run flavors_ctx = flavors.FlavorsGenerator(self.context) flavors_ctx.setup() # Assertions self.assertEqual(flavors_ctx.context["flavors"], {"flavor_name": { "flavor_key": "flavor_value" }}) mock_clients.assert_called_with(self.context["admin"]["credential"]) mock_create.assert_called_with(name="flavor_name", ram=2048, vcpus=3, disk=10, ephemeral=3, swap=5) mock_create().set_keys.assert_called_with({"key": "value"}) mock_create().to_dict.assert_called_with()
def test_cleanup(self, mock_clients): # Setup and mock real_context = { "flavors": { "flavor_name": { "flavor_name": "flavor_name", "id": "flavor_name" } }, "admin": { "endpoint": mock.MagicMock() }, "task": mock.MagicMock(), } # Run flavors_ctx = flavors.FlavorsGenerator(real_context) flavors_ctx.cleanup() # Assertions mock_clients.assert_called_with(real_context["admin"]["endpoint"]) mock_flavors_delete = mock_clients().nova().flavors.delete mock_flavors_delete.assert_called_with("flavor_name")