def test_invalid_uri_type(self): ref_type = 'ftp' ref_path = '/localhost/images/{}'.format(self.image_name) ref_uri = '{}://{}'.format(ref_type, ref_path) with pytest.raises(exceptions.TestcloudImageError): image.Image(ref_uri)
def test_non_existant_instance(self, monkeypatch): ref_name = 'test-123' ref_image = image.Image('file:///someimage.qcow2') stub_listdir = mock.Mock() stub_listdir.return_value = [] monkeypatch.setattr(os, 'listdir', stub_listdir) test_instance = instance.find_instance(ref_name, ref_image) assert test_instance is None
def test_file_uri(self): ref_type = 'file' ref_path = '/srv/images/{}'.format(self.image_name) ref_uri = '{}://{}'.format(ref_type, ref_path) test_image = image.Image(ref_uri) test_data = test_image._process_uri(ref_uri) assert len(test_data) == self.len_data assert test_data['type'] == ref_type assert test_data['name'] == self.image_name assert test_data['path'] == ref_path
def test_http_ur1(self): ref_type = 'http' ref_path = 'localhost/images/{}'.format(self.image_name) ref_uri = '{}://{}'.format(ref_type, ref_path) test_image = image.Image(ref_uri) test_data = test_image._process_uri(ref_uri) assert len(test_data) == self.len_data assert test_data['type'] == ref_type assert test_data['name'] == self.image_name assert test_data['path'] == ref_path
def test_find_exist_instance(self, monkeypatch): ref_name = 'test-123' ref_image = image.Image('file:///someimage.qcow2') ref_path = os.path.join(self.conf.DATA_DIR, 'instances/{}'.format(ref_name)) stub_listdir = mock.Mock() stub_listdir.return_value = [ref_name] monkeypatch.setattr(os, 'listdir', stub_listdir) test_instance = instance.find_instance(ref_name, ref_image) assert test_instance.path == ref_path
def _prepare_image(self, distro, release, flavor, arch): '''Use testcloud to prepare an image for local booting :param str distro: Distro to use in image discovery :param str release: Distro's release to use in image discovery :param str flavor: base-image flavor to use in image discovery :param str arch: arch to use in image discovery :raises CheckbImageNotFoundError: when base image of the required type is not found :raises CheckbImageError: for errors in preparing the image with testcloud ''' tc_image = None try: if config.get_config().force_imageurl: img_url = config.get_config().imageurl else: log.debug( "Looking for image with DISTRO: %s, RELEASE: %s, FLAVOR: %s, ARCH: %s" % (distro, release, flavor, arch)) img_url = ImageFinder.get_latest(distro=distro, release=release, flavor=flavor, arch=arch) except exc.CheckbImageNotFoundError as e: log.error(e) raise log.debug("Preparing image {} for task {}".format(img_url, self.uuid)) try: tc_image = image.Image(img_url) # symlink the image instead of copying it to the testcloud dir, because our user only # expects image handling in checkb dirs, and we remove all minion instances # immediately after task execution anyway tc_image.prepare(copy=False) except TestcloudImageError as e: log.exception(e) raise exc.CheckbImageError( "There was an error while preparing the " "testcloud image", e) return tc_image
def test_invalid_uri(self): ref_uri = 'leprechaunhandywork' with pytest.raises(exceptions.TestcloudImageError): image.Image(ref_uri)