def test_delete(self): self.stack = parser.Stack(self.ctx, 'delete_test', parser.Template({})) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) self.assertNotEqual(db_s, None) self.stack.delete() db_s = db_api.stack_get(self.ctx, stack_id) self.assertEqual(db_s, None) self.assertEqual(self.stack.state, self.stack.DELETE_COMPLETE)
def test_delete_rollback(self): self.stack = parser.Stack(self.ctx, 'delete_rollback_test', parser.Template({}), disable_rollback=False) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) self.assertNotEqual(db_s, None) self.stack.delete(action=self.stack.ROLLBACK) db_s = db_api.stack_get(self.ctx, stack_id) self.assertEqual(db_s, None) self.assertEqual(self.stack.state, self.stack.ROLLBACK_COMPLETE)
def test_delete_badaction(self): self.stack = parser.Stack(self.ctx, 'delete_badaction_test', parser.Template({})) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) self.assertNotEqual(db_s, None) self.stack.delete(action="wibble") db_s = db_api.stack_get(self.ctx, stack_id) self.assertNotEqual(db_s, None) self.assertEqual(self.stack.state, self.stack.DELETE_FAILED)
def test_stack_update(self): stack_name = 'service_update_test_stack' params = {'foo': 'bar'} template = '{ "Template": "data" }' old_stack = get_wordpress_stack(stack_name, self.ctx) sid = old_stack.store() s = db_api.stack_get(self.ctx, sid) stack = get_wordpress_stack(stack_name, self.ctx) self.m.StubOutWithMock(parser, 'Stack') self.m.StubOutWithMock(parser.Stack, 'load') parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(parser, 'Parameters') parser.Template(template).AndReturn(stack.t) parser.Parameters(stack_name, stack.t, params).AndReturn(stack.parameters) parser.Stack(self.ctx, stack.name, stack.t, stack.parameters).AndReturn(stack) self.m.StubOutWithMock(stack, 'validate') stack.validate().AndReturn(None) self.m.ReplayAll() result = self.man.update_stack(self.ctx, old_stack.identifier(), template, params, {}) self.assertEqual(result, old_stack.identifier()) self.assertTrue(isinstance(result, dict)) self.assertTrue(result['stack_id']) self.m.VerifyAll()
def test_stack_update_verify_err(self): stack_name = 'service_update_verify_err_test_stack' params = {'foo': 'bar'} template = '{ "Template": "data" }' old_stack = get_wordpress_stack(stack_name, self.ctx) old_stack.store() sid = old_stack.store() s = db_api.stack_get(self.ctx, sid) stack = get_wordpress_stack(stack_name, self.ctx) self.m.StubOutWithMock(parser, 'Stack') self.m.StubOutWithMock(parser.Stack, 'load') parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(parser, 'Parameters') parser.Template(template).AndReturn(stack.t) parser.Parameters(stack_name, stack.t, params).AndReturn(stack.parameters) parser.Stack(self.ctx, stack.name, stack.t, stack.parameters).AndReturn(stack) self.m.StubOutWithMock(stack, 'validate') stack.validate().AndRaise( exception.StackValidationFailed(message='fubar')) self.m.ReplayAll() self.assertRaises(exception.StackValidationFailed, self.man.update_stack, self.ctx, old_stack.identifier(), template, params, {}) self.m.VerifyAll()
def test_stack_update_verify_err(self): stack_name = "service_update_verify_err_test_stack" params = {"foo": "bar"} template = '{ "Template": "data" }' old_stack = get_wordpress_stack(stack_name, self.ctx) old_stack.store() sid = old_stack.store() s = db_api.stack_get(self.ctx, sid) stack = get_wordpress_stack(stack_name, self.ctx) self.m.StubOutWithMock(parser, "Stack") self.m.StubOutWithMock(parser.Stack, "load") parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) self.m.StubOutWithMock(parser, "Template") self.m.StubOutWithMock(parser, "Parameters") parser.Template(template).AndReturn(stack.t) parser.Parameters(stack_name, stack.t, params).AndReturn(stack.parameters) parser.Stack(self.ctx, stack.name, stack.t, stack.parameters).AndReturn(stack) self.m.StubOutWithMock(stack, "validate") error = "fubar" stack.validate().AndReturn(error) self.m.ReplayAll() result = self.man.update_stack(self.ctx, old_stack.identifier(), template, params, {}) self.assertEqual(result, {"Description": error}) self.m.VerifyAll()
def test_stack_update(self): stack_name = "service_update_test_stack" params = {"foo": "bar"} template = '{ "Template": "data" }' old_stack = get_wordpress_stack(stack_name, self.ctx) sid = old_stack.store() s = db_api.stack_get(self.ctx, sid) stack = get_wordpress_stack(stack_name, self.ctx) self.m.StubOutWithMock(parser, "Stack") self.m.StubOutWithMock(parser.Stack, "load") parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) self.m.StubOutWithMock(parser, "Template") self.m.StubOutWithMock(parser, "Parameters") parser.Template(template).AndReturn(stack.t) parser.Parameters(stack_name, stack.t, params).AndReturn(stack.parameters) parser.Stack(self.ctx, stack.name, stack.t, stack.parameters).AndReturn(stack) self.m.StubOutWithMock(stack, "validate") stack.validate().AndReturn(None) self.m.ReplayAll() result = self.man.update_stack(self.ctx, old_stack.identifier(), template, params, {}) self.assertEqual(result, old_stack.identifier()) self.assertTrue(isinstance(result, dict)) self.assertTrue(result["stack_id"]) self.m.VerifyAll()
def test_wordpress_single_instance_stack_delete(self): ctx = create_context(self.m, tenant='test_delete_tenant') stack = get_wordpress_stack('test_stack', ctx) setup_mocks(self.m, stack) self.m.ReplayAll() stack_id = stack.store() stack.create() db_s = db_api.stack_get(ctx, stack_id) self.assertNotEqual(db_s, None) self.assertNotEqual(stack.resources['WebServer'], None) self.assertTrue(stack.resources['WebServer'].instance_id > 0) stack.delete() self.assertEqual(stack.resources['WebServer'].state, 'DELETE_COMPLETE') self.assertEqual(db_api.stack_get(ctx, stack_id), None) self.assertEqual(db_s.status, 'DELETE_COMPLETE')
def test_wordpress_single_instance_stack_delete(self): ctx = create_context(self.m, tenant='test_delete_tenant') stack = get_wordpress_stack('test_stack', ctx) fc = setup_mocks(self.m, stack) self.m.ReplayAll() stack_id = stack.store() stack.create() db_s = db_api.stack_get(ctx, stack_id) self.assertNotEqual(db_s, None) self.assertNotEqual(stack.resources['WebServer'], None) self.assertTrue(stack.resources['WebServer'].resource_id > 0) self.m.StubOutWithMock(fc.client, 'get_servers_9999') get = fc.client.get_servers_9999 get().AndRaise(service.clients.novaclient.exceptions.NotFound(404)) mox.Replay(get) stack.delete() self.assertEqual(stack.resources['WebServer'].state, 'DELETE_COMPLETE') self.assertEqual(db_api.stack_get(ctx, stack_id), None) self.assertEqual(db_s.status, 'DELETE_COMPLETE')
def test_stack_delete(self): stack_name = 'service_delete_test_stack' stack = get_wordpress_stack(stack_name, self.ctx) sid = stack.store() s = db_api.stack_get(self.ctx, sid) self.m.StubOutWithMock(parser.Stack, 'load') parser.Stack.load(self.ctx, stack=s).AndReturn(stack) self.m.ReplayAll() self.assertEqual(self.man.delete_stack(self.ctx, stack.identifier()), None) self.m.VerifyAll()
def test_stack_delete(self): stack_name = "service_delete_test_stack" stack = get_wordpress_stack(stack_name, self.ctx) sid = stack.store() s = db_api.stack_get(self.ctx, sid) self.m.StubOutWithMock(parser.Stack, "load") # self.m.StubOutWithMock(threadgroup, 'ThreadGroup') # threadgroup.ThreadGroup(stack_name).AndReturn(DummyThreadGroup()) parser.Stack.load(self.ctx, stack=s).AndReturn(stack) self.m.ReplayAll() self.assertEqual(self.man.delete_stack(self.ctx, stack.identifier()), None) self.m.VerifyAll()
def test_stack_update_verify_err(self): stack_name = 'service_update_verify_err_test_stack' params = {'foo': 'bar'} template = '{ "Template": "data" }' old_stack = get_wordpress_stack(stack_name, self.ctx) old_stack.store() sid = old_stack.store() s = db_api.stack_get(self.ctx, sid) stack = get_wordpress_stack(stack_name, self.ctx) self.m.StubOutWithMock(parser, 'Stack') self.m.StubOutWithMock(parser.Stack, 'load') parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(parser, 'Parameters') parser.Template(template).AndReturn(stack.t) parser.Parameters(stack_name, stack.t, params).AndReturn(stack.parameters) parser.Stack(self.ctx, stack.name, stack.t, stack.parameters).AndReturn(stack) self.m.StubOutWithMock(stack, 'validate') stack.validate().AndRaise(exception.StackValidationFailed( message='fubar')) self.m.ReplayAll() self.assertRaises( exception.StackValidationFailed, self.man.update_stack, self.ctx, old_stack.identifier(), template, params, {}) self.m.VerifyAll()
def test_stack_update_verify_err(self): stack_name = 'service_update_verify_err_test_stack' params = {'foo': 'bar'} template = '{ "Template": "data" }' old_stack = get_wordpress_stack(stack_name, self.ctx) old_stack.store() sid = old_stack.store() s = db_api.stack_get(self.ctx, sid) stack = get_wordpress_stack(stack_name, self.ctx) self.m.StubOutWithMock(parser, 'Stack') self.m.StubOutWithMock(parser.Stack, 'load') parser.Stack.load(self.ctx, stack=s).AndReturn(old_stack) self.m.StubOutWithMock(parser, 'Template') self.m.StubOutWithMock(parser, 'Parameters') parser.Template(template).AndReturn(stack.t) parser.Parameters(stack_name, stack.t, params).AndReturn(stack.parameters) parser.Stack(self.ctx, stack.name, stack.t, stack.parameters).AndReturn(stack) self.m.StubOutWithMock(stack, 'validate') error = 'fubar' stack.validate().AndReturn(error) self.m.ReplayAll() result = self.man.update_stack(self.ctx, old_stack.identifier(), template, params, {}) self.assertEqual(result, {'Description': error}) self.m.VerifyAll()