Ejemplo n.º 1
0
    def create_volume(
        self,
        ctxt,
        volume,
        host,
        request_spec,
        filter_properties,
        allow_reschedule=True,
        snapshot_id=None,
        image_id=None,
        source_volid=None,
    ):

        request_spec_p = jsonutils.to_primitive(request_spec)
        self.cast(
            ctxt,
            self.make_msg(
                "create_volume",
                volume_id=volume["id"],
                request_spec=request_spec_p,
                filter_properties=filter_properties,
                allow_reschedule=allow_reschedule,
                snapshot_id=snapshot_id,
                image_id=image_id,
                source_volid=source_volid,
            ),
            topic=rpc.queue_get_for(ctxt, self.topic, host),
            version="1.4",
        )
Ejemplo n.º 2
0
def _decode_hmc_values(hmc_ref):
    """Decrypts any sensitive HMC values that were encrypted in the DB"""
    if hmc_ref is not None:
        hmc_ref = jsonutils.to_primitive(hmc_ref)
        #Make sure to DeCrypt the Password after retrieving from the database
        ## del two lines by lixx
        #if hmc_ref.get('password') is not None:
        #    hmc_ref['password'] = EncryptHandler().decode(hmc_ref['password'])
    return hmc_ref
Ejemplo n.º 3
0
 def manage_existing(self, ctxt, topic, volume_id,
                     request_spec=None, filter_properties=None):
     cctxt = self.client.prepare(version='1.5')
     request_spec_p = jsonutils.to_primitive(request_spec)
     return cctxt.cast(ctxt, 'manage_existing',
                       topic=topic,
                       volume_id=volume_id,
                       request_spec=request_spec_p,
                       filter_properties=filter_properties)
Ejemplo n.º 4
0
 def retype(self, ctxt, topic, volume_id,
            request_spec=None, filter_properties=None):
     request_spec_p = jsonutils.to_primitive(request_spec)
     return self.cast(ctxt, self.make_msg(
         'retype',
         topic=topic,
         volume_id=volume_id,
         request_spec=request_spec_p,
         filter_properties=filter_properties),
         version='1.4')
Ejemplo n.º 5
0
def notify(context, publisher_id, event_type, priority, payload):
    """Sends a notification using the specified driver

    :param publisher_id: the source worker_type.host of the message
    :param event_type:   the literal type of event (ex. Instance Creation)
    :param priority:     patterned after the enumeration of Python logging
                         levels in the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
    :param payload:       A python dictionary of attributes

    Outgoing message format includes the above parameters, and appends the
    following:

    message_id
      a UUID representing the id for this notification

    timestamp
      the GMT timestamp the notification was sent at

    The composite message will be constructed as a dictionary of the above
    attributes, which will then be sent via the transport mechanism defined
    by the driver.

    Message example::

        {'message_id': str(uuid.uuid4()),
         'publisher_id': 'compute.host1',
         'timestamp': timeutils.utcnow(),
         'priority': 'WARN',
         'event_type': 'compute.create_instance',
         'payload': {'instance_id': 12, ... }}

    """
    if priority not in log_levels:
        raise BadPriorityException(
            _('%s not in valid priorities') % priority)

    # Ensure everything is JSON serializable.
    payload = jsonutils.to_primitive(payload, convert_instances=True)

    msg = dict(message_id=str(uuid.uuid4()),
               publisher_id=publisher_id,
               event_type=event_type,
               priority=priority,
               payload=payload,
               timestamp=str(timeutils.utcnow()))

    for driver in _get_drivers():
        try:
            driver.notify(context, msg)
        except Exception as e:
            LOG.exception(_("Problem '%(e)s' attempting to "
                            "send to notification system. "
                            "Payload=%(payload)s")
                          % dict(e=e, payload=payload))
Ejemplo n.º 6
0
    def setUp(self):
        self.context = context.get_admin_context()
        vol = {}
        vol['host'] = 'fake_host'
        vol['availability_zone'] = FLAGS.storage_availability_zone
        vol['status'] = "available"
        vol['attach_status'] = "detached"
        volume = db.volume_create(self.context, vol)

        snpshot = {
            'volume_id': 'fake_id',
            'status': "creating",
            'progress': '0%',
            'volume_size': 0,
            'display_name': 'fake_name',
            'display_description': 'fake_description'}
        snapshot = db.snapshot_create(self.context, snpshot)
        self.fake_volume = jsonutils.to_primitive(volume)
        self.fake_snapshot = jsonutils.to_primitive(snapshot)
        super(VolumeRpcAPITestCase, self).setUp()
Ejemplo n.º 7
0
    def setUp(self):
        super(VolumeRpcAPITestCase, self).setUp()
        self.context = context.get_admin_context()
        vol = {}
        vol["host"] = "fake_host"
        vol["availability_zone"] = CONF.storage_availability_zone
        vol["status"] = "available"
        vol["attach_status"] = "detached"
        volume = db.volume_create(self.context, vol)

        snpshot = {
            "volume_id": "fake_id",
            "status": "creating",
            "progress": "0%",
            "volume_size": 0,
            "display_name": "fake_name",
            "display_description": "fake_description",
        }
        snapshot = db.snapshot_create(self.context, snpshot)
        self.fake_volume = jsonutils.to_primitive(volume)
        self.fake_snapshot = jsonutils.to_primitive(snapshot)
Ejemplo n.º 8
0
    def migrate_volume_to_host(self, ctxt, topic, volume_id, host,
                               force_host_copy=False, request_spec=None,
                               filter_properties=None):

        cctxt = self.client.prepare(version='1.3')
        request_spec_p = jsonutils.to_primitive(request_spec)
        return cctxt.cast(ctxt, 'migrate_volume_to_host',
                          topic=topic,
                          volume_id=volume_id,
                          host=host,
                          force_host_copy=force_host_copy,
                          request_spec=request_spec_p,
                          filter_properties=filter_properties)
Ejemplo n.º 9
0
    def create_volume(self, ctxt, topic, volume_id, snapshot_id=None,
                      image_id=None, request_spec=None,
                      filter_properties=None):

        cctxt = self.client.prepare(version='1.2')
        request_spec_p = jsonutils.to_primitive(request_spec)
        return cctxt.cast(ctxt, 'create_volume',
                          topic=topic,
                          volume_id=volume_id,
                          snapshot_id=snapshot_id,
                          image_id=image_id,
                          request_spec=request_spec_p,
                          filter_properties=filter_properties)
Ejemplo n.º 10
0
 def migrate_volume_to_host(self, ctxt, topic, volume_id, host,
                            force_host_copy=False, request_spec=None,
                            filter_properties=None):
     request_spec_p = jsonutils.to_primitive(request_spec)
     return self.cast(ctxt, self.make_msg(
         'migrate_volume_to_host',
         topic=topic,
         volume_id=volume_id,
         host=host,
         force_host_copy=force_host_copy,
         request_spec=request_spec_p,
         filter_properties=filter_properties),
         version='1.3')
Ejemplo n.º 11
0
 def create_volume(self, ctxt, topic, volume_id, snapshot_id=None,
                   image_id=None, request_spec=None,
                   filter_properties=None):
     request_spec_p = jsonutils.to_primitive(request_spec)
     return self.cast(ctxt, self.make_msg(
         'create_volume',
         topic=topic,
         volume_id=volume_id,
         snapshot_id=snapshot_id,
         image_id=image_id,
         request_spec=request_spec_p,
         filter_properties=filter_properties),
         version='1.2')
Ejemplo n.º 12
0
    def setUp(self):
        super(VolumeRpcAPITestCase, self).setUp()
        self.context = context.get_admin_context()
        vol = {}
        vol['host'] = 'fake_host'
        vol['availability_zone'] = CONF.storage_availability_zone
        vol['status'] = "available"
        vol['attach_status'] = "detached"
        vol['metadata'] = {"test_key": "test_val"}
        volume = db.volume_create(self.context, vol)

        snpshot = {
            'volume_id': 'fake_id',
            'status': "creating",
            'progress': '0%',
            'volume_size': 0,
            'display_name': 'fake_name',
            'display_description': 'fake_description'}
        snapshot = db.snapshot_create(self.context, snpshot)
        self.fake_volume = jsonutils.to_primitive(volume)
        self.fake_volume_metadata = volume["volume_metadata"]
        self.fake_snapshot = jsonutils.to_primitive(snapshot)
        self.fake_reservations = ["RESERVATION"]
Ejemplo n.º 13
0
    def create_consistencygroup(self, ctxt, topic, group_id,
                                request_spec_list=None,
                                filter_properties_list=None):

        cctxt = self.client.prepare(version='1.6')
        request_spec_p_list = []
        for request_spec in request_spec_list:
            request_spec_p = jsonutils.to_primitive(request_spec)
            request_spec_p_list.append(request_spec_p)

        return cctxt.cast(ctxt, 'create_consistencygroup',
                          topic=topic,
                          group_id=group_id,
                          request_spec_list=request_spec_p_list,
                          filter_properties_list=filter_properties_list)
Ejemplo n.º 14
0
    def create_volume(self, ctxt, volume, host,
                      request_spec, filter_properties,
                      allow_reschedule=True,
                      snapshot_id=None, image_id=None,
                      source_volid=None):

        cctxt = self.client.prepare(server=host, version='1.4')
        request_spec_p = jsonutils.to_primitive(request_spec)
        cctxt.cast(ctxt, 'create_volume',
                   volume_id=volume['id'],
                   request_spec=request_spec_p,
                   filter_properties=filter_properties,
                   allow_reschedule=allow_reschedule,
                   snapshot_id=snapshot_id,
                   image_id=image_id,
                   source_volid=source_volid),
Ejemplo n.º 15
0
    def _test_volume_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')

        if 'rpcapi_class' in kwargs:
            rpcapi_class = kwargs['rpcapi_class']
            del kwargs['rpcapi_class']
        else:
            rpcapi_class = volume_rpcapi.VolumeAPI
        rpcapi = rpcapi_class()
        expected_retval = 'foo' if method == 'call' else None

        expected_version = kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION)

        if 'request_spec' in kwargs:
            spec = jsonutils.to_primitive(kwargs['request_spec'])
            kwargs['request_spec'] = spec

        expected_msg = rpcapi.make_msg(method, **kwargs)
        if 'volume' in expected_msg['args']:
            volume = expected_msg['args']['volume']
            del expected_msg['args']['volume']
            expected_msg['args']['volume_id'] = volume['id']
        if 'snapshot' in expected_msg['args']:
            snapshot = expected_msg['args']['snapshot']
            del expected_msg['args']['snapshot']
            expected_msg['args']['snapshot_id'] = snapshot['id']
        if 'host' in expected_msg['args']:
            del expected_msg['args']['host']
        if 'dest_host' in expected_msg['args']:
            dest_host = expected_msg['args']['dest_host']
            dest_host_dict = {'host': dest_host.host,
                              'capabilities': dest_host.capabilities}
            del expected_msg['args']['dest_host']
            expected_msg['args']['host'] = dest_host_dict
        if 'new_volume' in expected_msg['args']:
            volume = expected_msg['args']['new_volume']
            del expected_msg['args']['new_volume']
            expected_msg['args']['new_volume_id'] = volume['id']

        expected_msg['version'] = expected_version

        if 'host' in kwargs:
            host = kwargs['host']
        else:
            host = kwargs['volume']['host']
        expected_topic = '%s:%s' % (CONF.volume_topic, host)

        self.fake_args = None
        self.fake_kwargs = None

        def _fake_rpc_method(*args, **kwargs):
            self.fake_args = args
            self.fake_kwargs = kwargs
            if expected_retval:
                return expected_retval

        self.stubs.Set(rpc, rpc_method, _fake_rpc_method)

        retval = getattr(rpcapi, method)(ctxt, **kwargs)

        self.assertEqual(retval, expected_retval)
        expected_args = [ctxt, expected_topic, expected_msg]
        for arg, expected_arg in zip(self.fake_args, expected_args):
            self.assertEqual(arg, expected_arg)
Ejemplo n.º 16
0
    def _test_volume_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')

        if 'rpcapi_class' in kwargs:
            rpcapi_class = kwargs['rpcapi_class']
            del kwargs['rpcapi_class']
        else:
            rpcapi_class = volume_rpcapi.VolumeAPI
        rpcapi = rpcapi_class()
        expected_retval = 'foo' if method == 'call' else None

        target = {
            "version": kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION)
        }

        if 'request_spec' in kwargs:
            spec = jsonutils.to_primitive(kwargs['request_spec'])
            kwargs['request_spec'] = spec

        expected_msg = copy.deepcopy(kwargs)
        if 'volume' in expected_msg:
            volume = expected_msg['volume']
            del expected_msg['volume']
            expected_msg['volume_id'] = volume['id']
        if 'snapshot' in expected_msg:
            snapshot = expected_msg['snapshot']
            del expected_msg['snapshot']
            expected_msg['snapshot_id'] = snapshot['id']
        if 'host' in expected_msg:
            del expected_msg['host']
        if 'dest_host' in expected_msg:
            dest_host = expected_msg['dest_host']
            dest_host_dict = {'host': dest_host.host,
                              'capabilities': dest_host.capabilities}
            del expected_msg['dest_host']
            expected_msg['host'] = dest_host_dict
        if 'new_volume' in expected_msg:
            volume = expected_msg['new_volume']
            del expected_msg['new_volume']
            expected_msg['new_volume_id'] = volume['id']

        if 'host' in kwargs:
            host = kwargs['host']
        else:
            host = kwargs['volume']['host']

        target['server'] = host
        target['topic'] = '%s.%s' % (CONF.volume_topic, host)

        self.fake_args = None
        self.fake_kwargs = None

        def _fake_prepare_method(*args, **kwds):
            for kwd in kwds:
                self.assertEqual(kwds[kwd], target[kwd])
            return rpcapi.client

        def _fake_rpc_method(*args, **kwargs):
            self.fake_args = args
            self.fake_kwargs = kwargs
            if expected_retval:
                return expected_retval

        self.stubs.Set(rpcapi.client, "prepare", _fake_prepare_method)
        self.stubs.Set(rpcapi.client, rpc_method, _fake_rpc_method)

        retval = getattr(rpcapi, method)(ctxt, **kwargs)

        self.assertEqual(retval, expected_retval)
        expected_args = [ctxt, method]

        for arg, expected_arg in zip(self.fake_args, expected_args):
            self.assertEqual(arg, expected_arg)

        for kwarg, value in self.fake_kwargs.items():
            self.assertEqual(value, expected_msg[kwarg])
Ejemplo n.º 17
0
    def _test_volume_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')

        if 'rpcapi_class' in kwargs:
            rpcapi_class = kwargs['rpcapi_class']
            del kwargs['rpcapi_class']
        else:
            rpcapi_class = volume_rpcapi.VolumeAPI
        rpcapi = rpcapi_class()
        expected_retval = 'foo' if method == 'call' else None

        target = {
            "version": kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION)
        }

        if 'request_spec' in kwargs:
            spec = jsonutils.to_primitive(kwargs['request_spec'])
            kwargs['request_spec'] = spec

        expected_msg = copy.deepcopy(kwargs)
        if 'volume' in expected_msg:
            volume = expected_msg['volume']
            del expected_msg['volume']
            expected_msg['volume_id'] = volume['id']
        if 'snapshot' in expected_msg:
            snapshot = expected_msg['snapshot']
            del expected_msg['snapshot']
            expected_msg['snapshot_id'] = snapshot['id']
        if 'host' in expected_msg:
            del expected_msg['host']
        if 'dest_host' in expected_msg:
            dest_host = expected_msg['dest_host']
            dest_host_dict = {
                'host': dest_host.host,
                'capabilities': dest_host.capabilities
            }
            del expected_msg['dest_host']
            expected_msg['host'] = dest_host_dict
        if 'new_volume' in expected_msg:
            volume = expected_msg['new_volume']
            del expected_msg['new_volume']
            expected_msg['new_volume_id'] = volume['id']

        if 'host' in kwargs:
            host = kwargs['host']
        else:
            host = kwargs['volume']['host']

        target['server'] = host
        target['topic'] = '%s.%s' % (CONF.volume_topic, host)

        self.fake_args = None
        self.fake_kwargs = None

        def _fake_prepare_method(*args, **kwds):
            for kwd in kwds:
                self.assertEqual(kwds[kwd], target[kwd])
            return rpcapi.client

        def _fake_rpc_method(*args, **kwargs):
            self.fake_args = args
            self.fake_kwargs = kwargs
            if expected_retval:
                return expected_retval

        self.stubs.Set(rpcapi.client, "prepare", _fake_prepare_method)
        self.stubs.Set(rpcapi.client, rpc_method, _fake_rpc_method)

        retval = getattr(rpcapi, method)(ctxt, **kwargs)

        self.assertEqual(retval, expected_retval)
        expected_args = [ctxt, method]

        for arg, expected_arg in zip(self.fake_args, expected_args):
            self.assertEqual(arg, expected_arg)

        for kwarg, value in self.fake_kwargs.items():
            self.assertEqual(value, expected_msg[kwarg])
Ejemplo n.º 18
0
    def _test_volume_api(self, method, rpc_method, **kwargs):
        ctxt = context.RequestContext('fake_user', 'fake_project')

        if 'rpcapi_class' in kwargs:
            rpcapi_class = kwargs['rpcapi_class']
            del kwargs['rpcapi_class']
        else:
            rpcapi_class = volume_rpcapi.VolumeAPI
        rpcapi = rpcapi_class()
        expected_retval = 'foo' if method == 'call' else None

        expected_version = kwargs.pop('version', rpcapi.BASE_RPC_API_VERSION)

        if 'request_spec' in kwargs:
            spec = jsonutils.to_primitive(kwargs['request_spec'])
            kwargs['request_spec'] = spec

        expected_msg = rpcapi.make_msg(method, **kwargs)
        if 'volume' in expected_msg['args']:
            volume = expected_msg['args']['volume']
            del expected_msg['args']['volume']
            expected_msg['args']['volume_id'] = volume['id']
        if 'snapshot' in expected_msg['args']:
            snapshot = expected_msg['args']['snapshot']
            del expected_msg['args']['snapshot']
            expected_msg['args']['snapshot_id'] = snapshot['id']
        if 'host' in expected_msg['args']:
            del expected_msg['args']['host']
        if 'dest_host' in expected_msg['args']:
            dest_host = expected_msg['args']['dest_host']
            dest_host_dict = {
                'host': dest_host.host,
                'capabilities': dest_host.capabilities
            }
            del expected_msg['args']['dest_host']
            expected_msg['args']['host'] = dest_host_dict
        if 'new_volume' in expected_msg['args']:
            volume = expected_msg['args']['new_volume']
            del expected_msg['args']['new_volume']
            expected_msg['args']['new_volume_id'] = volume['id']

        expected_msg['version'] = expected_version

        if 'host' in kwargs:
            host = kwargs['host']
        else:
            host = kwargs['volume']['host']
        expected_topic = '%s.%s' % (CONF.volume_topic, host)

        self.fake_args = None
        self.fake_kwargs = None

        def _fake_rpc_method(*args, **kwargs):
            self.fake_args = args
            self.fake_kwargs = kwargs
            if expected_retval:
                return expected_retval

        self.stubs.Set(rpc, rpc_method, _fake_rpc_method)

        retval = getattr(rpcapi, method)(ctxt, **kwargs)

        self.assertEqual(retval, expected_retval)
        expected_args = [ctxt, expected_topic, expected_msg]
        for arg, expected_arg in zip(self.fake_args, expected_args):
            self.assertEqual(arg, expected_arg)
Ejemplo n.º 19
0
 def serialize_entity(context, entity):
     return jsonutils.to_primitive(entity, convert_instances=True)