コード例 #1
0
    def __init__(self):
        """
        Contructor of the class region
        """
        # Get the region list
        # GET http://cloud.lab.fiware.org:4730/v3/OS-EP-FILTER/endpoint_groups

        if not self.regions:
            keystone_url = KEYSTONE_URL + '/' + AUTH_API_V2

            a = AuthorizationManager(identity_url=keystone_url, api_version=AUTH_API_V2)

            # Get the Admin token to validate the access_token
            adm_token = a.get_auth_token(username=ADM_USER, password=ADM_PASS, tenant_id=ADM_TENANT_ID,
                                         tenant_name=ADM_TENANT_NAME,
                                         user_domain_name=USER_DOMAIN_NAME)

            s = requests.Session()
            s.headers.update({X_AUTH_TOKEN_HEADER: adm_token})

            keystone_url = KEYSTONE_URL + '/' + AUTH_API_V3 + '/' + REGION_LIST_API_V3
            response = s.get(keystone_url)

            r = json.loads(response.text)

            endpoint_groups = r['endpoint_groups']

            for i in range(0, len(endpoint_groups)):
                # If the specific endpoint_groups has not a filters, it is not a correct
                # region and we discard it.
                region_filter = endpoint_groups[i]['filters']
                if region_filter and 'region_id' in region_filter:
                    self.regions.append(region_filter['region_id'])

            logger_api.debug(self.regions)
コード例 #2
0
    def test_get_auth_token_from_keystone_v3_without_header(self, m):
        """
        Check the obtention of a authorized token with v3.

        :param m: Request mock decorator.
        :return: Nothing
        """
        auth = AuthorizationManager(identity_url='http://fake_url', api_version=AUTH_API_V3)

        # Make sure that there is no auth token
        AuthorizationManager.auth_token = None

        m.post('http://fake_url/auth/tokens', json=self.validate_info_v3)

        try:
            auth.get_auth_token(username='******', password='******', tenant_id='fake tenant',
                                user_domain_name="Default")
        except KeyError as e:
            self.assertEquals(e.message, "x-subject-token", 'The missing header is not the expected one.')
コード例 #3
0
    def test_get_auth_token_from_keystone_v3_without_header(self, m):
        """
        Check the obtention of a authorized token with v3.

        :param m: Request mock decorator.
        :return: Nothing
        """
        auth = AuthorizationManager(identity_url='http://fake_url',
                                    api_version=AUTH_API_V3)

        # Make sure that there is no auth token
        AuthorizationManager.auth_token = None

        m.post('http://fake_url/auth/tokens', json=self.validate_info_v3)

        try:
            auth.get_auth_token(username='******',
                                password='******',
                                tenant_id='fake tenant',
                                user_domain_name="Default")
        except KeyError as e:
            self.assertEquals(e.message, "x-subject-token",
                              'The missing header is not the expected one.')
コード例 #4
0
    def test_get_auth_token_from_keystone_v2(self, m):
        """
        Check the obtention of a authorized token with v2.

        :param m: Request mock decorator.
        :return: Nothing
        """
        auth = AuthorizationManager(identity_url='http://fake_url', api_version=AUTH_API_V2)

        # Make sure that there is no auth token
        AuthorizationManager.auth_token = None

        m.post('http://fake_url/tokens', json=self.validate_info_v2)

        auth_token = auth.get_auth_token(username='******', password='******', tenant_id='fake tenant')

        self.assertEquals(auth_token, self.idExpected, 'The expected auth token is not the same')
コード例 #5
0
    def test_get_auth_token_from_keystone_v2(self, m):
        """
        Check the obtention of a authorized token with v2.

        :param m: Request mock decorator.
        :return: Nothing
        """
        auth = AuthorizationManager(identity_url='http://fake_url',
                                    api_version=AUTH_API_V2)

        # Make sure that there is no auth token
        AuthorizationManager.auth_token = None

        m.post('http://fake_url/tokens', json=self.validate_info_v2)

        auth_token = auth.get_auth_token(username='******',
                                         password='******',
                                         tenant_id='fake tenant')

        self.assertEquals(auth_token, self.idExpected,
                          'The expected auth token is not the same')
コード例 #6
0
    def __init__(self):
        """
        Contructor of the class region
        """
        # Get the region list
        # GET http://cloud.lab.fiware.org:4730/v3/OS-EP-FILTER/endpoint_groups

        if not self.regions:
            keystone_url = KEYSTONE_URL + '/' + AUTH_API_V2

            a = AuthorizationManager(identity_url=keystone_url,
                                     api_version=AUTH_API_V2)

            # Get the Admin token to validate the access_token
            adm_token = a.get_auth_token(username=ADM_USER,
                                         password=ADM_PASS,
                                         tenant_id=ADM_TENANT_ID,
                                         tenant_name=ADM_TENANT_NAME,
                                         user_domain_name=USER_DOMAIN_NAME)

            s = requests.Session()
            s.headers.update({X_AUTH_TOKEN_HEADER: adm_token})

            keystone_url = KEYSTONE_URL + '/' + AUTH_API_V3 + '/' + REGION_LIST_API_V3
            response = s.get(keystone_url)

            r = json.loads(response.text)

            endpoint_groups = r['endpoint_groups']

            for i in range(0, len(endpoint_groups)):
                # If the specific endpoint_groups has not a filters, it is not a correct
                # region and we discard it.
                region_filter = endpoint_groups[i]['filters']
                if region_filter and 'region_id' in region_filter:
                    self.regions.append(region_filter['region_id'])

            logger_api.debug(self.regions)