コード例 #1
0
ファイル: config.py プロジェクト: aswadr/rally
    def _download_image(self):
        img_path = os.path.join(self.data_dir, self.image_name)
        if os.path.isfile(img_path):
            return

        try:
            response = requests.get(CONF.tempest.img_url, stream=True)
        except requests.ConnectionError as err:
            msg = _("Failed to download image. "
                    "Possibly there is no connection to Internet. "
                    "Error: %s.") % (str(err) or "unknown")
            raise exceptions.TempestConfigCreationFailure(msg)

        if response.status_code == 200:
            with open(img_path + ".tmp", "wb") as img_file:
                for chunk in response.iter_content(chunk_size=1024):
                    if chunk:  # filter out keep-alive new chunks
                        img_file.write(chunk)
                        img_file.flush()
            os.rename(img_path + ".tmp", img_path)
        else:
            if response.status_code == 404:
                msg = _("Failed to download image. " "Image was not found.")
            else:
                msg = _("Failed to download image. "
                        "HTTP error code %d.") % response.status_code
            raise exceptions.TempestConfigCreationFailure(msg)
コード例 #2
0
ファイル: config.py プロジェクト: zioc/rally
def _download_image(image_path, image=None):
    if image:
        LOG.debug("Downloading image '%s' "
                  "from Glance to %s" % (image.name, image_path))
        with open(image_path, "wb") as image_file:
            for chunk in image.data():
                image_file.write(chunk)
    else:
        LOG.debug("Downloading image from %s "
                  "to %s" % (CONF.tempest.img_url, image_path))
        try:
            response = requests.get(CONF.tempest.img_url, stream=True)
        except requests.ConnectionError as err:
            msg = _("Failed to download image. "
                    "Possibly there is no connection to Internet. "
                    "Error: %s.") % (str(err) or "unknown")
            raise exceptions.TempestConfigCreationFailure(msg)

        if response.status_code == 200:
            with open(image_path, "wb") as image_file:
                for chunk in response.iter_content(chunk_size=1024):
                    if chunk:  # filter out keep-alive new chunks
                        image_file.write(chunk)
                        image_file.flush()
        else:
            if response.status_code == 404:
                msg = _("Failed to download image. Image was not found.")
            else:
                msg = _("Failed to download image. "
                        "HTTP error code %d.") % response.status_code
            raise exceptions.TempestConfigCreationFailure(msg)

    LOG.debug("The image has been successfully downloaded!")
コード例 #3
0
ファイル: config.py プロジェクト: kambiz-aghaiepour/rally
 def _set_compute_images(self, section_name='compute'):
     glanceclient = self.clients.glance()
     image_list = [
         img for img in glanceclient.images.list()
         if img.status.lower() == 'active' and img.name is not None
         and 'cirros' in img.name
     ]
     # Upload new images if there are no
     # necessary images in the cloud (cirros)
     while len(image_list) < 2:
         now = (datetime.datetime.fromtimestamp(
             time.time()).strftime('%Y_%m_%d_%H_%M_%S'))
         try:
             image = glanceclient.images.create(name=('cirros_%s' % now),
                                                disk_format='qcow2',
                                                container_format='bare')
             image.update(data=open(self.img_path, 'rb'))
             image_list.append(image)
         except Exception as e:
             msg = _('There are no desired images (cirros) or only one and '
                     'new image could not be created.\n'
                     'Reason: %s') % e.message
             raise exceptions.TempestConfigCreationFailure(message=msg)
     self.conf.set(section_name, 'image_ref', image_list[0].id)
     self.conf.set(section_name, 'image_ref_alt', image_list[1].id)
コード例 #4
0
    def test_setup_failure_on_tempest_configuration(self, mock_gen,
                                                    mock_is_installed,
                                                    mock_is_cfg, mock_mkdir):
        mock_gen.side_effect = exceptions.TempestConfigCreationFailure()

        benchmark = tempest.Tempest(self.context)

        self.assertRaises(exceptions.BenchmarkSetupFailure, benchmark.setup)
        self.assertEqual(1, mock_is_cfg.call_count)
コード例 #5
0
ファイル: config.py プロジェクト: SunilMamillapalli/rally
 def _load_img(self):
     cirros_url = ('http://download.cirros-cloud.net/%s/%s' %
                   (CONF.image.cirros_version, CONF.image.cirros_image))
     try:
         response = urllib2.urlopen(cirros_url)
     except urllib2.URLError as err:
         msg = _('Error on downloading cirros image, possibly'
                 ' no connection to Internet with message %s') % str(err)
         raise exceptions.TempestConfigCreationFailure(message=msg)
     if response.getcode() == httplib.OK:
         with open(self.img_path, 'wb') as img_file:
             img_file.write(response.read())
     else:
         if response.getcode() == httplib.NOT_FOUND:
             msg = _('Error on downloading cirros image, possibly'
                     'invalid cirros_version or cirros_image in rally.conf')
         else:
             msg = _('Error on downloading cirros image, '
                     'HTTP error code %s') % response.getcode()
         raise exceptions.TempestConfigCreationFailure(message=msg)
コード例 #6
0
ファイル: config.py プロジェクト: kambiz-aghaiepour/rally
 def _load_img(self):
     cirros_url = ('http://download.cirros-cloud.net/%s/%s' %
                   (CONF.image.cirros_version, CONF.image.cirros_image))
     try:
         response = requests.get(cirros_url, stream=True)
     except requests.ConnectionError as err:
         msg = _('Error on downloading cirros image, possibly'
                 ' no connection to Internet with message %s') % str(err)
         raise exceptions.TempestConfigCreationFailure(message=msg)
     if response.status_code == 200:
         with open(self.img_path + '.tmp', 'wb') as img_file:
             for chunk in response.iter_content(chunk_size=1024):
                 if chunk:  # filter out keep-alive new chunks
                     img_file.write(chunk)
                     img_file.flush()
         os.rename(self.img_path + '.tmp', self.img_path)
     else:
         if response.status_code == 404:
             msg = _('Error on downloading cirros image, possibly'
                     'invalid cirros_version or cirros_image in rally.conf')
         else:
             msg = _('Error on downloading cirros image, '
                     'HTTP error code %s') % response.getcode()
         raise exceptions.TempestConfigCreationFailure(message=msg)
コード例 #7
0
ファイル: config.py プロジェクト: Frostman/rally
 def _set_compute_flavors(self):
     novaclient = self.clients.nova()
     flavor_list = sorted(novaclient.flavors.list(),
                          key=lambda flv: flv.ram)
     # Create new flavors if they are missing
     while len(flavor_list) < 2:
         now = (datetime.datetime.fromtimestamp(
             time.time()).strftime('%Y_%m_%d_%H_%M_%S'))
         try:
             flv = novaclient.flavors.create("m1.tiny_%s" % now, 512, 1, 1)
             flavor_list.append(flv)
         except Exception:
             msg = _('There are no desired flavors or only one and '
                     'new flavor could not be created')
             raise exceptions.TempestConfigCreationFailure(message=msg)
     self.conf.set('compute', 'flavor_ref', flavor_list[0].id)
     self.conf.set('compute', 'flavor_ref_alt', flavor_list[1].id)
コード例 #8
0
ファイル: config.py プロジェクト: Frostman/rally
 def __init__(self, deploy_id):
     self.endpoint = db.deployment_get(deploy_id)['endpoints'][0]
     self.clients = osclients.Clients(endpoint.Endpoint(**self.endpoint))
     try:
         self.keystoneclient = self.clients.verified_keystone()
     except exceptions.InvalidAdminException:
         msg = _('Admin permission is required to run tempest. User %s '
                 'doesn\'t have admin role') % self.endpoint['username']
         raise exceptions.TempestConfigCreationFailure(message=msg)
     self.available_services = [
         service['name']
         for service in self.keystoneclient.service_catalog.get_data()
     ]
     self.conf = configparser.ConfigParser()
     self.conf.read(os.path.join(os.path.dirname(__file__), 'config.ini'))
     self.deploy_id = deploy_id
     self.data_path = os.path.join(os.path.expanduser('~'), '.rally',
                                   'tempest', 'data')
     if not os.path.exists(self.data_path):
         os.makedirs(self.data_path)
     self.img_path = os.path.join(self.data_path, CONF.image.cirros_image)
     if not os.path.isfile(self.img_path):
         self._load_img()