def create_eip(self, t, stack, resource_name): rsrc = eip.ElasticIp(resource_name, t['Resources'][resource_name], stack) self.assertIsNone(rsrc.validate()) scheduler.TaskRunner(rsrc.create)() self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state) return rsrc
def create_eip(self, t, stack, resource_name): resource = eip.ElasticIp(resource_name, t['Resources'][resource_name], stack) self.assertEqual(None, resource.validate()) scheduler.TaskRunner(resource.create)() self.assertEqual(eip.ElasticIp.CREATE_COMPLETE, resource.state) return resource
def create_eip(self, t, stack, resource_name): resource_defns = stack.t.resource_definitions(stack) rsrc = eip.ElasticIp(resource_name, resource_defns[resource_name], stack) self.assertIsNone(rsrc.validate()) scheduler.TaskRunner(rsrc.create)() self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state) return rsrc
def test_eip_with_exception(self): self.m.StubOutWithMock(self.fc.floating_ips, 'create') nova.NovaClientPlugin._create().AndReturn(self.fc) self.fc.floating_ips.create().AndRaise(fakes_v1_1.fake_exception()) self.m.ReplayAll() t = template_format.parse(eip_template) stack = utils.parse_stack(t) resource_name = 'IPAddress' resource_defns = stack.t.resource_definitions(stack) rsrc = eip.ElasticIp(resource_name, resource_defns[resource_name], stack) self.assertRaises(nova_exceptions.NotFound, rsrc.handle_create) self.m.VerifyAll()
def test_delete_eip_with_exception(self): self.m.StubOutWithMock(self.fc.floating_ips, 'delete') eip.ElasticIp.nova().MultipleTimes().AndReturn(self.fc) self.fc.floating_ips.delete(mox.IsA(object)).AndRaise( clients.novaclient.exceptions.NotFound('fake_falure')) self.fc.servers.get(mox.IsA(object)).AndReturn(False) self.m.ReplayAll() t = template_format.parse(eip_template) stack = utils.parse_stack(t) resource_name = 'IPAddress' rsrc = eip.ElasticIp(resource_name, t['Resources'][resource_name], stack) rsrc.resource_id = 'fake_id' rsrc.handle_delete() self.m.VerifyAll()
def test_eip_with_exception(self): self.m.StubOutWithMock(self.fc.floating_ips, 'create') eip.ElasticIp.nova().MultipleTimes().AndReturn(self.fc) self.fc.floating_ips.create().AndRaise( clients.novaclient.exceptions.NotFound('fake_falure')) self.m.ReplayAll() t = template_format.parse(eip_template) stack = utils.parse_stack(t) resource_name = 'IPAddress' rsrc = eip.ElasticIp(resource_name, t['Resources'][resource_name], stack) self.assertRaises(clients.novaclient.exceptions.NotFound, rsrc.handle_create) self.m.VerifyAll()
def test_delete_eip_with_exception(self): self.m.StubOutWithMock(self.fc.floating_ips, 'delete') nova.NovaClientPlugin._create().AndReturn(self.fc) self.fc.floating_ips.delete(mox.IsA(object)).AndRaise( fakes_v1_1.fake_exception()) self.fc.servers.get(mox.IsA(object)).AndReturn(False) self.m.ReplayAll() t = template_format.parse(eip_template) stack = utils.parse_stack(t) resource_name = 'IPAddress' resource_defns = stack.t.resource_definitions(stack) rsrc = eip.ElasticIp(resource_name, resource_defns[resource_name], stack) rsrc.resource_id = 'fake_id' rsrc.handle_delete() self.m.VerifyAll()
def test_delete_eip_successful_if_eip_associate_failed(self): floating_ip = mox.IsA(object) floating_ip.ip = '172.24.4.13' floating_ip.id = '9037272b-6875-42e6-82e9-4342d5925da4' self.m.StubOutWithMock(self.fc.floating_ips, 'create') self.fc.floating_ips.create().AndReturn(floating_ip) server = self.fc.servers.list()[0] nova.NovaClientPlugin._create().AndReturn(self.fc) self.fc.servers.get('WebServer').MultipleTimes().AndReturn(server) self.m.StubOutWithMock(self.fc.servers, 'add_floating_ip') self.fc.servers.add_floating_ip(server, floating_ip.ip, None).\ AndRaise(nova_exceptions.BadRequest(400)) self.m.StubOutWithMock(self.fc.servers, 'remove_floating_ip') msg = ("ClientException: Floating ip 172.24.4.13 is not associated " "with instance 1234.") self.fc.servers.remove_floating_ip(server, floating_ip.ip).\ AndRaise(nova_exceptions.ClientException(422, msg)) self.m.StubOutWithMock(self.fc.floating_ips, 'delete') self.fc.floating_ips.delete(mox.IsA(object)) self.m.ReplayAll() t = template_format.parse(eip_template) stack = utils.parse_stack(t) resource_name = 'IPAddress' resource_defns = stack.t.resource_definitions(stack) rsrc = eip.ElasticIp(resource_name, resource_defns[resource_name], stack) self.assertIsNone(rsrc.validate()) self.assertRaises(exception.ResourceFailure, scheduler.TaskRunner(rsrc.create)) self.assertEqual((rsrc.CREATE, rsrc.FAILED), rsrc.state) # to delete the eip scheduler.TaskRunner(rsrc.delete)() self.assertEqual((rsrc.DELETE, rsrc.COMPLETE), rsrc.state) self.m.VerifyAll()