Exemple #1
0
 def test_get_public_endpoint(self):
     self.stub_auth()
     session = base.Session(USERNAME, PASSWORD, client_fixtures.PROJECT_ID,
                            AUTH_URL)
     endpoint = session.get_endpoint('volume')
     self.assertEqual(endpoint, client_fixtures.VOLUME_PUBLIC_ENDPOINT)
     endpoint = session.get_endpoint('image')
     self.assertEqual(endpoint, client_fixtures.IMAGE_PUBLIC_ENDPOINT)
Exemple #2
0
 def test_init(self):
     self.stub_auth()
     session = base.Session(USERNAME, PASSWORD, client_fixtures.PROJECT_ID,
                            AUTH_URL)
     self.assertEqual(session.token, client_fixtures.TOKEN_ID)
     self.assertEqual(session.user_id, client_fixtures.USER_ID)
     self.assertEqual(session.project_id, client_fixtures.PROJECT_ID)
     self.assertTrue(session.is_admin)
Exemple #3
0
 def test_get_internal_endpoint(self):
     self.stub_auth()
     session = base.Session(USERNAME,
                            PASSWORD,
                            client_fixtures.PROJECT_ID,
                            AUTH_URL,
                            endpoint_type='internalURL')
     endpoint = session.get_endpoint('volume')
     self.assertEqual(endpoint, client_fixtures.VOLUME_INTERNAL_ENDPOINT)
     endpoint = session.get_endpoint('image')
     self.assertEqual(endpoint, client_fixtures.IMAGE_INTERNAL_ENDPOINT)
Exemple #4
0
 def setUp(self):
     super(TestResourcesBase, self).setUp()
     self.stub_auth()
     self.session = base.Session(USERNAME, PASSWORD,
                                 client_fixtures.PROJECT_ID, AUTH_URL)
     # We can't add other stubs in subclasses setUp because
     # httpretty.dactivate() is called after this set_up (so during the
     # super call to this method in subclasses). and extra stubs will not
     # work. if you need extra stubs to be done during setUp, write them
     # in an 'extra_set_up' method. instead of in the subclasses setUp
     if hasattr(self, 'extra_set_up'):
         self.extra_set_up()
Exemple #5
0
def perform_on_project(admin_name,
                       password,
                       project,
                       auth_url,
                       endpoint_type='publicURL',
                       region_name=None,
                       action='dump',
                       insecure=False):
    """Perform provided action on all resources of project.

    action can be: 'purge' or 'dump'
    """
    session = base.Session(admin_name, password, project, auth_url,
                           endpoint_type, region_name, insecure)
    error = None
    for rc in constants.RESOURCES_CLASSES:
        try:
            resources = globals()[rc](session)
            res_actions = {'purge': resources.purge, 'dump': resources.dump}
            res_actions[action]()
        except (exceptions.EndpointNotFound, api_exceptions.EndpointNotFound,
                neutronclient.common.exceptions.EndpointNotFound,
                cinderclient.exceptions.EndpointNotFound,
                novaclient.exceptions.EndpointNotFound, heatclient.openstack.
                common.apiclient.exceptions.EndpointNotFound,
                exceptions.ResourceNotEnabled):
            # If service is not in Keystone's services catalog, ignoring it
            pass
        except requests.exceptions.MissingSchema as e:
            logging.warning(
                'Some resources may not have been deleted, "{!s}" is '
                'improperly configured and returned: {!r}\n'.format(rc, e))
        except (ceilometerclient.exc.InvalidEndpoint,
                glanceclient.exc.InvalidEndpoint) as e:
            logging.warning("Unable to connect to {} endpoint : {}".format(
                rc, e.message))
            error = exceptions.InvalidEndpoint(rc)
        except (neutronclient.common.exceptions.NeutronClientException):
            # If service is not configured, ignoring it
            pass
    if error:
        raise error