コード例 #1
0
ファイル: common.py プロジェクト: zhenhappy/pycloudsigma
    def _get_persistent_image_uuid_and_pass(self):
        # Get a good persistent test image
        p_name = config.get('persistent_drive_name')
        p_pass = config.get('persistent_drive_ssh_password')

        if p_name is None:
            raise SkipTest('A persistent_drive_name must be stated in the '
                           'client configuration to execute this test')

        def _filter_drives(av_drives):
            for drive in av_drives:
                if p_name in drive['name'] and drive['status'] in \
                        ('mounted', 'unmounted', 'cloning_src',):
                    return drive['uuid']
            return None

        puuid = _filter_drives(cr.Drive().list_detail())
        if puuid is None:
            puuid = _filter_drives(cr.LibDrive().list_detail())
            if puuid is not None:
                client_drives = cr.Drive()
                clone_drive_def = {
                    'name': p_name,
                }
                cloned_drive = client_drives.clone(puuid, clone_drive_def)
                self._wait_for_status(cloned_drive['uuid'],
                                      'unmounted',
                                      timeout=self.TIMEOUT_DRIVE_CLONING,
                                      client=client_drives)
                puuid = cloned_drive['uuid']

        if puuid is None:
            raise SkipTest("There is no drive matching {}".format(p_name))

        return puuid, p_pass
コード例 #2
0
ファイル: common.py プロジェクト: GreatFruitOmsk/pycloudsigma
    def _get_persistent_image_uuid_and_pass(self):
        # Get a good persistant test image
        p_name = config.get('persistent_drive_name')
        p_pass = config.get('persistent_drive_ssh_password')

        if p_name is None:
            raise SkipTest('A persistent_drive_name must be stated in the client configuration to execute this test')

        puuid = None
        av_drives = cr.Drive().list_detail()
        for drive in av_drives:
            if p_name in drive['name']:
                puuid = drive['uuid']
                break

        if puuid is None:
            raise SkipTest("There is no drive matching {}".format(p_name))
        return puuid, p_pass
コード例 #3
0
    def __init__(self, api_endpoint=None, username=None, password=None, login_method=LOGIN_METHOD_BASIC):
        self.api_endpoint = api_endpoint if api_endpoint else config['api_endpoint']
        self.username = username if username else config['username']
        self.password = password if password else config['password']
        self.login_method = config.get('login_method', login_method)
        assert self.login_method in self.LOGIN_METHODS, 'Invalid value %r for login_method' % (login_method,)

        self._session = None
        self.resp = None
        self.response_hook = None
コード例 #4
0
    def _get_persistent_image_uuid_and_pass(self):
        # Get a good persistant test image
        p_name = config.get('persistent_drive_name')
        p_pass = config.get('persistent_drive_ssh_password')

        if p_name is None:
            raise SkipTest(
                'A persistent_drive_name must be stated in the client configuration to execute this test'
            )

        puuid = None
        av_drives = cr.Drive().list_detail()
        for drive in av_drives:
            if p_name in drive['name']:
                puuid = drive['uuid']
                break

        if puuid is None:
            raise SkipTest("There is no drive matching {}".format(p_name))
        return puuid, p_pass
コード例 #5
0
ファイル: utils.py プロジェクト: GreatFruitOmsk/pycloudsigma
    def __init__(self, name=None, suffix=None, dump_path=None, req_data_filter=None, resp_data_filter=None):
        self.name = name
        self.suffix = suffix
        self.tmp_name = None
        self.req_data_filter = req_data_filter
        self.resp_data_filter = resp_data_filter

        # If dump path not found/derived,
        if dump_path is None and config.get('dump_path') is not None:
            self.dump_path = os.path.join(os.path.expanduser(config['dump_path']))
        else:
            self.dump_path = dump_path
コード例 #6
0
    def __init__(self,
                 name=None,
                 suffix=None,
                 dump_path=None,
                 req_data_filter=None,
                 resp_data_filter=None):
        self.name = name
        self.suffix = suffix
        self.tmp_name = None
        self.req_data_filter = req_data_filter
        self.resp_data_filter = resp_data_filter

        # If dump path not found/derived,
        if dump_path is None and config.get('dump_path') is not None:
            self.dump_path = os.path.join(
                os.path.expanduser(config['dump_path']))
        else:
            self.dump_path = dump_path
コード例 #7
0
class DrivesBulk(BulkBase):
    CREATE_DRIVE_MEDIA = config.get('CREATE_DRIVE_MEDIA', 'disk')
    CREATE_DRIVE_SIZE = config.get('CREATE_DRIVE_SIZE', 10*1024**3)
    CREATE_DRIVE_DESCRIPTION = config.get('CREATE_DRIVE_DESCRIPTION', 'some descr')

    def __init__(self, media=CREATE_DRIVE_MEDIA, size=CREATE_DRIVE_SIZE,
                description=CREATE_DRIVE_DESCRIPTION,
                *args, **kwargs):
        super(DrivesBulk, self).__init__(*args, **kwargs)

        self.media = media
        self.size = size
        self.description = description

    def generate_definition(self):
        return {
            "media": self.media,
            "name": self.get_name(),
            "size": self.size,
            "meta": {
                "description": self.description,
                }
            }

    def create(self, count):
        """Creates a number of new drives

        @param count: the amount to be created
        """

        drives = []
        for _ in range(count):
            d = self.generate_definition()
            req = {
                    "objects": [d, ],
                }
            resp = self.c_drive.create(req)
            LOG.info('Created drive %r', resp['name'])
            drives.append(resp)
        return drives

    def delete(self, uuid, name):
        self.c_drive.delete(uuid)
        LOG.info('Deleted drive %r', name)

    def wipe(self):
        """Deletes all artifacts created by this identification prefix
        """
        resp = self.get_list()
        for d in resp:
            self.delete(d['uuid'], d['name'])

    def clone(self, count, source_name_or_uuid):
        """Creates a number of new drives, cloning from the given original.

        The source drive is first looked-up in the drives of the current account and then in the drives library

        @param count: the amount to be created
        @param source_name_or_uuid: either the UUID of the source or substring match of its name
        """
        source_drive = self.lookup(source_name_or_uuid)

        drives = []
        for _ in range(count):
            d = {
                    "media": source_drive['media'],
                    "name": self.get_name(),
                    "size": source_drive['size'],
                    "meta": source_drive['meta'],
                    "affinities": source_drive['affinities'],
                }
            resp = self.c_drive.clone(source_drive['uuid'], d)
            LOG.info('Cloned drive %r from %r', resp['name'], source_drive['name'])
            drives.append(resp)

        # Wait for all drives to finish clonning
        drives_uuids = [d['uuid'] for d in drives]

        def is_clonning_finished():

            existing_drives = self.get_detail()
            current_scenario_drives = [d for d in existing_drives if d['uuid'] in drives_uuids]
            current_scenario_drives_statuses = [d['status'] for d in current_scenario_drives]

            return current_scenario_drives_statuses

        statuses = is_clonning_finished()
        while 'cloning_dst' in statuses:
            time.sleep(10)
            drives_statuses_string = '\n'.join(['{}: {}'.format(uuid, status) for uuid, status in zip(drives_uuids, statuses)])
            LOG.info('Waiting for all drives cloning from {} to finish cloning:\n{}'.format(source_drive['uuid'],
                     drives_statuses_string))
            statuses = is_clonning_finished()

        # All finished print final statuses
        drives_statuses_string = '\n'.join(['{}: {}'.format(uuid, status) for uuid, status in zip(drives_uuids, statuses)])
        LOG.info('Finished cloning {} to drives:\n{}'.format(source_drive['uuid'], drives_statuses_string))

        return drives

    def clone_all(self, count=1):
        src_drives = self.get_detail()
        drives = []
        for drv in src_drives:
            if drv['status'] == 'unavailable':
                continue
            for i in range(int(count)):
                d = {
                        "media": drv['media'],
                        "name": 'clone_%s_%i' % (drv['name'], i),
                        "size": drv['size'],
                        "meta": drv['meta'],
                        "affinities": drv['affinities'],
                    }
                resp = self.c_drive.clone(drv['uuid'], d)
                LOG.info('Cloned drive %r from %r', resp['name'], drv['name'])
                drives.append(resp)
        return drives

    def get_list(self):
        """Queries the drives in this account with the given prefix
        """
        resp = self.c_drive.list(query_params={"fields": 'name,uuid'})
        resp = filter(lambda x: x['name'].startswith(self.id_prefix), resp)
        return resp

    def get_detail(self):
        resp = self.c_drive.list_detail()
        resp = filter(lambda x: x['name'].startswith(self.id_prefix), resp)
        return resp

    def lookup(self, name_or_uuid):
        resp = self.c_drive.list_detail()
        candidates = self.filter_by_name_uuid(resp, name_or_uuid)
        if not candidates:
            resp = self.c_drive.list_library_drives()
            candidates = self.filter_by_name_uuid(resp, name_or_uuid)
        if len(candidates) == 0:
            raise Exception("Could not find %s with lookup key %s" % (
                    self.__class__.__name__, name_or_uuid))
        return candidates[0]

    def get_by_uuids(self, uuids):
        """Queries the drives in this account with the given prefix
        """
        resp = self.c_drive.list_detail(query_params={"fields": 'name,uuid,status'})
        resp = filter(lambda x: x['uuid'] in uuids, resp)
        return resp