def test_get(self): metadata = { 'x-container-meta-usage-tripleo': 'plan', 'accept-ranges': 'bytes', 'x-storage-policy': 'Policy-0', 'connection': 'keep-alive', 'x-timestamp': '1447161410.72641', 'x-trans-id': 'tx1f41a9d34a2a437d8f8dd-00565dd486', 'content-type': 'application/json; charset=utf-8', 'x-versions-location': 'versions' } expected_plan = Plan(self.plan_name) expected_plan.metadata = metadata expected_plan.files = { 'some-name.yaml': { 'contents': "some fake contents", 'meta': {'file-type': 'environment'} }, } self.swiftclient.get_container = mock.MagicMock(return_value=( metadata, [ {'name': 'some-name.yaml'}, ]) ) self.swiftclient.get_object = mock.MagicMock(return_value=( {'x-object-meta-file-type': 'environment'}, "some fake contents" )) self.assertEqual(expected_plan.name, self.plan_store.get(self.plan_name).name) self.swiftclient.get_container.assert_called_with(self.plan_name) self.swiftclient.get_object.assert_called_with( 'overcloud', 'some-name.yaml')
def test_repr(self): plan = Plan('foo') plan_str = six.text_type(plan) self.assertEqual( {'Plan': { 'files': {}, 'name': 'foo', 'metadata': {} }}, yaml.safe_load(plan_str))
def test_update(self): expected_plan = Plan(self.plan_name) expected_plan.metadata = { 'x-container-meta-usage-tripleo': 'plan', 'accept-ranges': 'bytes', 'x-storage-policy': 'Policy-0', } expected_plan.files = { 'some-name.yaml': { 'contents': "some fake contents", 'meta': {'file-type': 'environment'} }, } self.swiftclient.put_object = mock.MagicMock() self.plan_store.update(self.plan_name, expected_plan.files) self.swiftclient.put_object.assert_called_with( self.plan_name, 'some-name.yaml', "some fake contents", headers={'x-object-meta-file-type': 'environment'} )
def get(self, plan_name): """Retrieves the files for a given container name Retrieves the files from the Swift container matching plan_name. :param plan_name: The name of the plan :type plan_name: str :return: a list of files :rtype list """ plan = Plan(plan_name) container = self.swiftclient.get_container(plan_name) plan.metadata = container[0] for data in container[1]: filename = data['name'] plan_obj = self.swiftclient.get_object(plan_name, filename) plan.files[filename] = {} plan.files[filename]['contents'] = plan_obj[1] meta_info = {k: v for (k, v) in plan_obj[0].items() if constants.OBJECT_META_KEY_PREFIX in k} if len(meta_info) > 0: plan.files[filename]['meta'] = \ meta.remove_key_prefix(meta_info) return plan
def test_plan(self): plan = Plan('overcloud') plan.metadata = { 'x-container-meta-usage-tripleo': 'plan', 'accept-ranges': 'bytes', 'x-storage-policy': 'Policy-0', 'connection': 'keep-alive', 'x-timestamp': self.timestamp, 'x-trans-id': 'tx1f41a9d34a2a437d8f8dd-00565dd486', 'content-type': 'application/json; charset=utf-8', 'x-versions-location': 'versions' } plan.files = { 'some-name.yaml': { 'contents': "some fake contents", 'meta': {'file-type': 'environment'} }, } expected_date = datetime.datetime.fromtimestamp( float(self.timestamp)) self.assertEqual(expected_date, plan.created_date(), "Date mismatch")
def test_update(self): expected_plan = Plan(self.plan_name) expected_plan.metadata = { 'x-container-meta-usage-tripleo': 'plan', 'accept-ranges': 'bytes', 'x-storage-policy': 'Policy-0', } expected_plan.files = { 'some-name.yaml': { 'contents': "some fake contents", 'meta': { 'file-type': 'environment' } }, } self.swiftclient.put_object = mock.MagicMock() self.plan_store.update(self.plan_name, expected_plan.files) self.swiftclient.put_object.assert_called_with( self.plan_name, 'some-name.yaml', "some fake contents", headers={'x-object-meta-file-type': 'environment'})
def test_plan(self): plan = Plan('overcloud') plan.metadata = { 'x-container-meta-usage-tripleo': 'plan', 'accept-ranges': 'bytes', 'x-storage-policy': 'Policy-0', 'connection': 'keep-alive', 'x-timestamp': self.timestamp, 'x-trans-id': 'tx1f41a9d34a2a437d8f8dd-00565dd486', 'content-type': 'application/json; charset=utf-8', 'x-versions-location': 'versions' } plan.files = { 'some-name.yaml': { 'contents': "some fake contents", 'meta': { 'file-type': 'environment' } }, } expected_date = datetime.datetime.fromtimestamp(float(self.timestamp)) self.assertEqual(expected_date, plan.created_date(), "Date mismatch")
def test_eq(self): self.assertEqual(Plan('foo'), Plan('foo')) self.assertNotEqual(Plan('bar'), Plan('foo')) self.assertNotEqual(Plan('bar'), None) class thing(object): pass self.assertNotEqual(Plan('bar'), thing())
def test_get(self): metadata = { 'x-container-meta-usage-tripleo': 'plan', 'accept-ranges': 'bytes', 'x-storage-policy': 'Policy-0', 'connection': 'keep-alive', 'x-timestamp': '1447161410.72641', 'x-trans-id': 'tx1f41a9d34a2a437d8f8dd-00565dd486', 'content-type': 'application/json; charset=utf-8', 'x-versions-location': 'versions' } expected_plan = Plan(self.plan_name) expected_plan.metadata = metadata expected_plan.files = { 'some-name.yaml': { 'contents': "some fake contents", 'meta': { 'file-type': 'environment' } }, } self.swiftclient.get_container = mock.MagicMock( return_value=(metadata, [ { 'name': 'some-name.yaml' }, ])) self.swiftclient.get_object = mock.MagicMock( return_value=({ 'x-object-meta-file-type': 'environment' }, "some fake contents")) self.assertEqual(expected_plan.name, self.plan_store.get(self.plan_name).name) self.swiftclient.get_container.assert_called_with(self.plan_name) self.swiftclient.get_object.assert_called_with('overcloud', 'some-name.yaml')