Exemple #1
0
 def one_key_pair(context, user_id, name):
     if name == 'key':
         return dict(test_keypair.fake_keypair,
                     name='key',
                     public_key='public_key')
     else:
         raise exc.KeypairNotFound(user_id=user_id, name=name)
Exemple #2
0
def _destroy_in_db(context, user_id, name):
    result = context.session.query(api_models.KeyPair).\
             filter_by(user_id=user_id).\
             filter_by(name=name).\
             delete()
    if not result:
        raise exception.KeypairNotFound(user_id=user_id, name=name)
Exemple #3
0
 def db_key_pair_get(context, user_id, name):
     if name == self.existing_key_name and not self.key_destroyed:
         return dict(test_keypair.fake_keypair,
                     name=self.existing_key_name,
                     public_key=self.pub_key,
                     fingerprint=self.fingerprint)
     else:
         raise exception.KeypairNotFound(user_id=user_id, name=name)
Exemple #4
0
 def one_key_pair(context, user_id, name):
     if name in ['key', 'new-key']:
         return dict(test_keypair.fake_keypair,
                     name=name,
                     public_key='public_key',
                     **kwargs)
     else:
         raise exc.KeypairNotFound(user_id=user_id, name=name)
Exemple #5
0
    def get_by_name(cls, context, user_id, name, localonly=False):
        if localonly:
            # There is no longer a "local" (main) table for keypairs, so this
            # will always return nothing now
            raise exception.KeypairNotFound(user_id=user_id, name=name)

        db_keypair = cls._get_from_db(context, user_id, name)
        return cls._from_db_object(context, cls(), db_keypair)
Exemple #6
0
 def db_key_pair_get(context, user_id, name):
     if name == self.existing_key_name:
         return {
             'name': self.existing_key_name,
             'public_key': self.pub_key,
             'fingerprint': self.fingerprint
         }
     else:
         raise exception.KeypairNotFound(user_id=user_id, name=name)
    def get_keypair_at_top(self, ctxt, user_id, name):
        if not CONF.cells.enable:
            return

        cctxt = self.client.prepare(version='1.37')
        keypair = cctxt.call(ctxt, 'get_keypair_at_top', user_id=user_id,
                             name=name)
        if keypair is None:
            raise exception.KeypairNotFound(user_id=user_id,
                                            name=name)
        return keypair
Exemple #8
0
    def test_get_by_name_main(self, mock_api_get, mock_kp_get):
        mock_api_get.side_effect = exception.KeypairNotFound(user_id='foo',
                                                             name='foo')
        mock_kp_get.return_value = fake_keypair

        keypair_obj = keypair.KeyPair.get_by_name(self.context, 'fake-user',
                                                  'foo-keypair')
        self.compare_obj(keypair_obj, fake_keypair)

        mock_kp_get.assert_called_once_with(self.context, 'fake-user',
                                            'foo-keypair')
        mock_api_get.assert_called_once_with(self.context, 'fake-user',
                                             'foo-keypair')
def _get_from_db(context, user_id, name=None, limit=None, marker=None):
    query = context.session.query(api_models.KeyPair).\
            filter(api_models.KeyPair.user_id == user_id)
    if name is not None:
        db_keypair = query.filter(api_models.KeyPair.name == name).\
                     first()
        if not db_keypair:
            raise exception.KeypairNotFound(user_id=user_id, name=name)
        return db_keypair

    marker_row = None
    if marker is not None:
        marker_row = context.session.query(api_models.KeyPair).\
            filter(api_models.KeyPair.name == marker).\
            filter(api_models.KeyPair.user_id == user_id).first()
        if not marker_row:
            raise exception.MarkerNotFound(marker=marker)

    query = sqlalchemyutils.paginate_query(
        query, api_models.KeyPair, limit, ['name'], marker=marker_row)

    return query.all()
Exemple #10
0
 def _db_key_pair_get(context, user_id, name):
     raise exception.KeypairNotFound(user_id=user_id, name=name)
Exemple #11
0
def _fake_destroy_in_db(context, user_id, name):
    if not (user_id and name):
        raise Exception()

    if name != 'FAKE':
        raise exception.KeypairNotFound(user_id=user_id, name=name)
Exemple #12
0
def _fake_get_from_db(context, user_id, name=None, limit=None, marker=None):
    if name:
        if name != 'FAKE':
            raise exception.KeypairNotFound(user_id=user_id, name=name)
        return fake_keypair('FAKE')
    return [fake_keypair('FAKE')]