def test_resources_with_stack_name(self, mock_find): stack_id = '1234' stack_name = 'test_stack' stk = stack.Stack(id=stack_id, name=stack_name) mock_find.return_value = stk self.verify_list(self.proxy.resources, resource.Resource, method_args=[stack_id], expected_args=[], expected_kwargs={ 'stack_name': stack_name, 'stack_id': stack_id }) mock_find.assert_called_once_with(mock.ANY, stack_id, ignore_missing=False)
def test_create(self): resp = mock.Mock() resp.json = mock.Mock(return_value=FAKE_CREATE_RESPONSE) sess = mock.Mock() sess.post = mock.Mock(return_value=resp) sot = stack.Stack(FAKE) sot.create(sess) url = '/stacks' body = sot._attrs.copy() body.pop('id', None) body.pop('name', None) sess.post.assert_called_with(url, endpoint_filter=sot.service, json=body) self.assertEqual(FAKE_ID, sot.id) self.assertEqual(FAKE_NAME, sot.name)
def test_get_stack_template_with_stack_identity(self, mock_find): stack_id = '1234' stack_name = 'test_stack' stk = stack.Stack(id=stack_id, name=stack_name) mock_find.return_value = stk self._verify('openstack.proxy.Proxy._get', self.proxy.get_stack_template, method_args=['IDENTITY'], expected_args=[stack_template.StackTemplate], expected_kwargs={ 'requires_id': False, 'stack_name': stack_name, 'stack_id': stack_id }) mock_find.assert_called_once_with(mock.ANY, 'IDENTITY', ignore_missing=False)
def test_update(self): sess = mock.Mock() sess.default_microversion = None mock_response = mock.Mock() mock_response.status_code = 200 mock_response.headers = {} mock_response.json.return_value = {} sess.put = mock.Mock(return_value=mock_response) sot = stack.Stack(**FAKE) body = sot._body.dirty.copy() sot.update(sess) sess.put.assert_called_with('/stacks/%s/%s' % (FAKE_NAME, FAKE_ID), headers={}, microversion=None, json=body)
def test_list_stacks(self): fake_stacks = [ self.stack, fakes.make_fake_stack(self.getUniqueString('id'), self.getUniqueString('name')) ] self.register_uris([ dict(method='GET', uri='{endpoint}/stacks'.format( endpoint=fakes.ORCHESTRATION_ENDPOINT), json={"stacks": fake_stacks}), ]) stacks = self.cloud.list_stacks() self.assertEqual([ f.toDict() for f in self.cloud._normalize_stacks( stack.Stack(**st) for st in fake_stacks) ], [f.toDict() for f in stacks]) self.assert_calls()
def test_search_stacks_filters(self): fake_stacks = [ self.stack, fakes.make_fake_stack(self.getUniqueString('id'), self.getUniqueString('name'), status='CREATE_FAILED') ] self.register_uris([ dict(method='GET', uri='{endpoint}/stacks'.format( endpoint=fakes.ORCHESTRATION_ENDPOINT), json={"stacks": fake_stacks}), ]) filters = {'status': 'FAILED'} stacks = self.cloud.search_stacks(filters=filters) self.assertEqual( self.cloud._normalize_stacks( stack.Stack(**st) for st in fake_stacks[1:]), stacks) self.assert_calls()
def test_make_it(self): sot = stack.Stack(**FAKE) self.assertEqual(FAKE['capabilities'], sot.capabilities) self.assertEqual(FAKE['creation_time'], sot.created_at) self.assertEqual(FAKE['description'], sot.description) self.assertTrue(sot.is_rollback_disabled) self.assertEqual(FAKE['id'], sot.id) self.assertEqual(FAKE['links'], sot.links) self.assertEqual(FAKE['notification_topics'], sot.notification_topics) self.assertEqual(FAKE['outputs'], sot.outputs) self.assertEqual(FAKE['parameters'], sot.parameters) self.assertEqual(FAKE['name'], sot.name) self.assertEqual(FAKE['status'], sot.status) self.assertEqual(FAKE['status_reason'], sot.status_reason) self.assertEqual(FAKE['template_description'], sot.template_description) self.assertEqual(FAKE['template_url'], sot.template_url) self.assertEqual(FAKE['timeout_mins'], sot.timeout_mins) self.assertEqual(FAKE['updated_time'], sot.updated_at)
def test_make_it(self): sot = stack.Stack(EXAMPLE) self.assertEqual(EXAMPLE['capabilities'], sot.capabilities) self.assertEqual(EXAMPLE['creation_time'], sot.creation_time) self.assertEqual(EXAMPLE['description'], sot.description) self.assertEqual(EXAMPLE['disable_rollback'], sot.disable_rollback) self.assertEqual(EXAMPLE['id'], sot.id) self.assertEqual(EXAMPLE['links'], sot.links) self.assertEqual(EXAMPLE['notification_topics'], sot.notification_topics) self.assertEqual(EXAMPLE['outputs'], sot.outputs) self.assertEqual(EXAMPLE['parameters'], sot.parameters) self.assertEqual(EXAMPLE['stack_name'], sot.stack_name) self.assertEqual(EXAMPLE['stack_status'], sot.stack_status) self.assertEqual(EXAMPLE['stack_status_reason'], sot.stack_status_reason) self.assertEqual(EXAMPLE['template_description'], sot.template_description) self.assertEqual(EXAMPLE['timeout_mins'], sot.timeout_mins) self.assertEqual(EXAMPLE['updated_time'], sot.updated_time)
def test_find(self, mock_find): sess = mock.Mock() sot = stack.Stack(FAKE) deleted_stack = mock.Mock(status='DELETE_COMPLETE') normal_stack = mock.Mock(status='CREATE_COMPLETE') mock_find.side_effect = [ None, normal_stack, deleted_stack, deleted_stack, ] self.assertIsNone(sot.find(sess, 'fake_name')) self.assertEqual(normal_stack, sot.find(sess, 'fake_name')) self.assertIsNone(sot.find(sess, 'fake_name', ignore_missing=True)) ex = self.assertRaises(exceptions.ResourceNotFound, sot.find, sess, 'fake_name', ignore_missing=False) self.assertEqual('ResourceNotFound: No stack found for fake_name', six.text_type(ex))
def test_list_stacks_filters(self): fake_stacks = [ self.stack, fakes.make_fake_stack(self.getUniqueString('id'), self.getUniqueString('name')) ] self.register_uris([ dict(method='GET', uri=self.get_mock_url( 'orchestration', 'public', append=['stacks'], qs_elements=['name=a', 'status=b'], ), json={"stacks": fake_stacks}), ]) stacks = self.cloud.list_stacks(name='a', status='b') self.assertEqual([ f.toDict() for f in self.cloud._normalize_stacks( stack.Stack(**st) for st in fake_stacks) ], [f.toDict() for f in stacks]) self.assert_calls()
def test_make_it(self): sot = stack.Stack(FAKE) self.assertEqual(FAKE['capabilities'], sot.capabilities) dt = datetime.datetime(2015, 3, 9, 12, 15, 57, 233772).replace(tzinfo=None) self.assertEqual(dt, sot.created_at.replace(tzinfo=None)) self.assertEqual(FAKE['description'], sot.description) self.assertTrue(sot.is_rollback_disabled) self.assertEqual(FAKE['id'], sot.id) self.assertEqual(FAKE['links'], sot.links) self.assertEqual(FAKE['notification_topics'], sot.notification_topics) self.assertEqual(FAKE['outputs'], sot.outputs) self.assertEqual(FAKE['parameters'], sot.parameters) self.assertEqual(FAKE['name'], sot.name) self.assertEqual(FAKE['status'], sot.status) self.assertEqual(FAKE['status_reason'], sot.status_reason) self.assertEqual(FAKE['template_description'], sot.template_description) self.assertEqual(FAKE['template_url'], sot.template_url) self.assertEqual(FAKE['timeout_mins'], sot.timeout_mins) dt = datetime.datetime(2015, 3, 9, 12, 30, 00, 000000).replace(tzinfo=None) self.assertEqual(dt, sot.updated_at.replace(tzinfo=None))
def get_stack(self, **data): return stack.Stack(data).get(self.session)
def create_stack(self, **data): return stack.Stack(data).create(self.session)