def test_image_scheme(self, mock_lbd, mock_http_req, mock_yaml): mock_lbd.return_value = LIST_BLOCK_DEVICES_SAMPLE drv = nailgun.Nailgun(PROVISION_SAMPLE_DATA) p_scheme = drv.partition_scheme i_scheme = drv.image_scheme expected_images = [] for fs in p_scheme.fss: if fs.mount not in PROVISION_SAMPLE_DATA['ks_meta']['image_data']: continue i_data = PROVISION_SAMPLE_DATA['ks_meta']['image_data'][fs.mount] expected_images.append( image.Image( uri=i_data['uri'], target_device=fs.device, format=i_data['format'], container=i_data['container'], )) expected_images = sorted(expected_images, key=lambda x: x.uri) for i, img in enumerate(sorted(i_scheme.images, key=lambda x: x.uri)): self.assertEqual(img.uri, expected_images[i].uri) self.assertEqual(img.target_device, expected_images[i].target_device) self.assertEqual(img.format, expected_images[i].format) self.assertEqual(img.container, expected_images[i].container) self.assertIsNone(img.size) self.assertIsNone(img.md5)
def test_image_scheme_with_checksums(self, mock_lbd, mock_http_req): fake_image_meta = { 'images': [{ 'raw_md5': 'fakeroot', 'raw_size': 1, 'container_name': 'fake_image.img.gz' }] } prop_mock = mock.PropertyMock(return_value=yaml.dump(fake_image_meta)) type(mock_http_req.return_value).text = prop_mock mock_lbd.return_value = LIST_BLOCK_DEVICES_SAMPLE p_data = PROVISION_SAMPLE_DATA.copy() drv = nailgun.Nailgun(p_data) p_scheme = drv.partition_scheme i_scheme = drv.image_scheme mock_http_req.assert_called_once_with( 'http://fake.host.org:123/imgs/fake_image.yaml') expected_images = [] for fs in p_scheme.fss: if fs.mount not in PROVISION_SAMPLE_DATA['ks_meta']['image_data']: continue i_data = PROVISION_SAMPLE_DATA['ks_meta']['image_data'][fs.mount] expected_images.append( image.Image( uri=i_data['uri'], target_device=fs.device, format=i_data['format'], container=i_data['container'], )) expected_images = sorted(expected_images, key=lambda x: x.uri) for i, img in enumerate(sorted(i_scheme.images, key=lambda x: x.uri)): self.assertEqual(img.uri, expected_images[i].uri) self.assertEqual(img.target_device, expected_images[i].target_device) self.assertEqual(img.format, expected_images[i].format) self.assertEqual(img.container, expected_images[i].container) self.assertEqual(img.size, fake_image_meta['images'][0]['raw_size']) self.assertEqual(img.md5, fake_image_meta['images'][0]['raw_md5'])
def test_image_scheme_with_checksums(self, mock_lbd, mock_image_meta): fake_image_meta = { 'images': [{ 'raw_md5': 'fakeroot', 'raw_size': 1, 'container_name': 'fake_image.img.gz' }] } mock_image_meta.return_value = fake_image_meta mock_lbd.return_value = LIST_BLOCK_DEVICES_SAMPLE p_data = PROVISION_SAMPLE_DATA.copy() drv = nailgun.Nailgun(p_data) p_scheme = drv.partition_scheme i_scheme = drv.image_scheme expected_images = [] for fs in p_scheme.fss: if fs.mount not in PROVISION_SAMPLE_DATA['ks_meta']['image_data']: continue i_data = PROVISION_SAMPLE_DATA['ks_meta']['image_data'][fs.mount] expected_images.append( image.Image( uri=i_data['uri'], target_device=fs.device, format=i_data['format'], container=i_data['container'], )) expected_images = sorted(expected_images, key=lambda x: x.uri) for i, img in enumerate(sorted(i_scheme.images, key=lambda x: x.uri)): self.assertEqual(img.uri, expected_images[i].uri) self.assertEqual(img.target_device, expected_images[i].target_device) self.assertEqual(img.format, expected_images[i].format) self.assertEqual(img.container, expected_images[i].container) self.assertEqual(img.size, fake_image_meta['images'][0]['raw_size']) self.assertEqual(img.md5, fake_image_meta['images'][0]['raw_md5'])