Esempio n. 1
0
    def setUpClass(cls):
        super(ObjectStorageFixture, cls).setUpClass()

        endpoint_config = UserAuthConfig()
        user_config = UserConfig()
        objectstorage_config = ObjectStorageConfig()
        objectstorage_api_config = ObjectStorageAPIConfig()

        auth_provider = AuthProvider()
        access_data = auth_provider.get_access_data(
            endpoint_config,
            user_config)

        service = access_data.get_service(
            objectstorage_config.identity_service_name)

        endpoint = service.get_endpoint(objectstorage_config.region)
        storage_url = endpoint.public_url
        auth_token = access_data.token.id_

        cls.base_container_name = objectstorage_api_config.base_container_name
        cls.base_object_name = objectstorage_api_config.base_object_name

        cls.client = ObjectStorageAPIClient(
                storage_url,
                auth_token)

        cls.behaviors = ObjectStorageAPI_Behaviors(client=cls.client)
Esempio n. 2
0
    def setUpClass(cls):
        super(ObjectStorageFixture, cls).setUpClass()

        endpoint_config = UserAuthConfig()
        user_config = UserConfig()
        objectstorage_config = ObjectStorageConfig()
        objectstorage_api_config = ObjectStorageAPIConfig()

        auth_provider = AuthProvider()
        access_data = auth_provider.get_access_data(endpoint_config,
                                                    user_config)

        service = access_data.get_service(
            objectstorage_config.identity_service_name)

        endpoint = service.get_endpoint(objectstorage_config.region)
        storage_url = endpoint.public_url
        auth_token = access_data.token.id_

        cls.base_container_name = objectstorage_api_config.base_container_name
        cls.base_object_name = objectstorage_api_config.base_object_name

        cls.client = ObjectStorageAPIClient(storage_url, auth_token)

        cls.behaviors = ObjectStorageAPI_Behaviors(client=cls.client)
Esempio n. 3
0
    def get_auth_data():
        """
        Authenticate and return a dictionary containing the storage url and
        auth token.
        """
        result = {
            'storage_url': None,
            'auth_token': None}

        endpoint_config = UserAuthConfig()
        user_config = UserConfig()
        objectstorage_config = ObjectStorageConfig()
        auth_provider = AuthProvider()
        access_data = auth_provider.get_access_data(
            endpoint_config, user_config)

        if endpoint_config.strategy.lower() == 'saio_tempauth':
            result['storage_url'] = access_data.storage_url
            result['auth_token'] = access_data.auth_token
        else:
            service = access_data.get_service(
                objectstorage_config.identity_service_name)
            endpoint = service.get_endpoint(objectstorage_config.region)
            result['storage_url'] = endpoint.public_url
            result['auth_token'] = access_data.token.id_

        return result
Esempio n. 4
0
    def setUpClass(cls):
        super(ComputeAdminFixture, cls).setUpClass()

        # Setup admin client
        auth_config = ComputeAdminAuthConfig()
        user_config = ComputeAdminUserConfig()
        access_data = AuthProvider.get_access_data(auth_config, user_config)
        admin_endpoint_config = ComputeAdminEndpointConfig()
        compute_service = access_data.get_service(
            admin_endpoint_config.compute_endpoint_name)
        url = compute_service.get_endpoint(
            admin_endpoint_config.region).public_url
        cls.admin_flavors_client = FlavorsClient(url, access_data.token.id_,
                                                 'json', 'json')
        cls.admin_servers_client = ServersClient(url, access_data.token.id_,
                                                 'json', 'json')
        cls.admin_server_behaviors = ServerBehaviors(cls.admin_servers_client,
                                                     cls.servers_config,
                                                     cls.images_config,
                                                     cls.flavors_config)
        cls.admin_images_client = ImagesClient(url, access_data.token.id_,
                                               'json', 'json')
        cls.admin_images_behaviors = ImageBehaviors(cls.admin_images_client,
                                                    cls.admin_servers_client,
                                                    cls.images_config)
        cls.admin_hosts_client = HostsClient(url, access_data.token.id_,
                                             'json', 'json')
        cls.admin_quotas_client = QuotasClient(url, access_data.token.id_,
                                               'json', 'json')
        cls.admin_servers_client.add_exception_handler(ExceptionHandler())
Esempio n. 5
0
    def setUpClass(cls):
        super(ComputeFixture, cls).setUpClass()
        cls.flavors_config = FlavorsConfig()
        cls.images_config = ImagesConfig()
        cls.servers_config = ServersConfig()
        cls.compute_endpoint = ComputeEndpointConfig()
        cls.marshalling = MarshallingConfig()

        cls.flavor_ref = cls.flavors_config.primary_flavor
        cls.flavor_ref_alt = cls.flavors_config.secondary_flavor
        cls.image_ref = cls.images_config.primary_image
        cls.image_ref_alt = cls.images_config.secondary_image
        cls.disk_path = cls.servers_config.instance_disk_path

        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                   cls.user_config)
        compute_service = access_data.get_service(
            cls.compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            cls.compute_endpoint.region).public_url
        # If a url override was provided, use that value instead
        if cls.compute_endpoint.compute_endpoint_url:
            url = '{0}/{1}'.format(cls.compute_endpoint.compute_endpoint_url,
                                   cls.user_config.tenant_id)

        cls.flavors_client = FlavorsClient(url, access_data.token.id_,
                                           cls.marshalling.serializer,
                                           cls.marshalling.deserializer)
        cls.servers_client = ServersClient(url, access_data.token.id_,
                                           cls.marshalling.serializer,
                                           cls.marshalling.deserializer)
        cls.images_client = ImagesClient(url, access_data.token.id_,
                                         cls.marshalling.serializer,
                                         cls.marshalling.deserializer)
        cls.keypairs_client = KeypairsClient(url, access_data.token.id_,
                                             cls.marshalling.serializer,
                                             cls.marshalling.deserializer)
        cls.security_groups_client = SecurityGroupsClient(
            url, access_data.token.id_, cls.marshalling.serializer,
            cls.marshalling.deserializer)
        cls.security_group_rule_client = SecurityGroupRulesClient(
            url, access_data.token.id_, cls.marshalling.serializer,
            cls.marshalling.deserializer)
        cls.rescue_client = RescueClient(url, access_data.token.id_,
                                         cls.marshalling.serializer,
                                         cls.marshalling.deserializer)
        cls.vnc_client = VncConsoleClient(url, access_data.token.id_,
                                         cls.marshalling.serializer,
                                         cls.marshalling.deserializer)
        cls.server_behaviors = ServerBehaviors(cls.servers_client,
                                               cls.servers_config,
                                               cls.images_config,
                                               cls.flavors_config)
        cls.image_behaviors = ImageBehaviors(cls.images_client,
                                             cls.servers_client,
                                             cls.images_config)
        cls.flavors_client.add_exception_handler(ExceptionHandler())
        cls.resources = ResourcePool()
Esempio n. 6
0
    def setUpClass(cls):
        super(AuthorizationTests, cls).setUpClass()
        cls.metadata = {'meta_key_1': 'meta_value_1',
                        'meta_key_2': 'meta_value_2'}
        cls.server = cls.server_behaviors.create_active_server(
            metadata=cls.metadata).entity
        cls.resources.add(cls.server.id, cls.servers_client.delete_server)

        image_name = rand_name('testimage')
        cls.image_meta = {'key1': 'value1', 'key2': 'value2'}
        image_resp = cls.servers_client.create_image(cls.server.id,
                                                     image_name,
                                                     cls.image_meta)
        assert image_resp.status_code == 202
        cls.image_id = cls.parse_image_id(image_resp)
        cls.image_behaviors.wait_for_image_status(
            cls.image_id, NovaImageStatusTypes.ACTIVE)
        cls.resources.add(cls.image_id, cls.images_client.delete_image)

        secondary_user = ComputeAuthorizationConfig()
        access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                   secondary_user)

        compute_service = access_data.get_service(
            cls.compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            cls.compute_endpoint.region).public_url

        cls.flavors_client = FlavorsClient(url, access_data.token.id_,
                                           'json', 'json')
        cls.servers_client = ServersClient(url, access_data.token.id_,
                                           'json', 'json')
        cls.images_client = ImagesClient(url, access_data.token.id_,
                                         'json', 'json')
        cls.flavors_client.add_exception_handler(ExceptionHandler())
Esempio n. 7
0
    def setUpClass(cls):
        """
        Initialize autoscale configs, behaviors and client
        """
        super(AutoscaleFixture, cls).setUpClass()
        cls.resources = ResourcePool()
        cls.autoscale_config = AutoscaleConfig()
        cls.endpoint_config = UserAuthConfig()
        user_config = UserConfig()
        access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                   user_config)

        autoscale_service = access_data.get_service(
            cls.autoscale_config.autoscale_endpoint_name)

        server_service = access_data.get_service(
            cls.autoscale_config.server_endpoint_name)
        server_url = server_service.get_endpoint(
            cls.autoscale_config.region).public_url

        cls.tenant_id = cls.autoscale_config.tenant_id
        env = os.environ['OSTNG_CONFIG_FILE']
        if 'dev' in env.lower():
            url = 'http://localhost:9000/v1.0/{0}'.format(cls.tenant_id)
        elif 'prod' in env.lower():
            url = 'https://autoscale.api.rackspacecloud.com/v1.0/{0}'.format(
                cls.tenant_id)
        else:
            url = autoscale_service.get_endpoint(
                cls.autoscale_config.region).public_url

        cls.autoscale_client = AutoscalingAPIClient(
            url, access_data.token.id_,
            'json', 'json')
        cls.server_client = ServersClient(
            server_url, access_data.token.id_,
            'json', 'json')
        cls.autoscale_behaviors = AutoscaleBehaviors(cls.autoscale_config,
                                                     cls.autoscale_client)
        cls.gc_name = cls.autoscale_config.gc_name
        cls.gc_cooldown = int(cls.autoscale_config.gc_cooldown)
        cls.gc_min_entities = int(cls.autoscale_config.gc_min_entities)
        cls.gc_min_entities_alt = int(cls.autoscale_config.gc_min_entities_alt)
        cls.gc_max_entities = int(cls.autoscale_config.gc_max_entities)
        cls.lc_name = cls.autoscale_config.lc_name
        cls.lc_flavor_ref = cls.autoscale_config.lc_flavor_ref
        cls.lc_image_ref = cls.autoscale_config.lc_image_ref
        cls.lc_image_ref_alt = cls.autoscale_config.lc_image_ref_alt
        cls.sp_name = rand_name(cls.autoscale_config.sp_name)
        cls.sp_cooldown = int(cls.autoscale_config.sp_cooldown)
        cls.sp_change = int(cls.autoscale_config.sp_change)
        cls.sp_change_percent = int(cls.autoscale_config.sp_change_percent)
        cls.sp_desired_capacity = int(cls.autoscale_config.sp_desired_capacity)
        cls.sp_policy_type = cls.autoscale_config.sp_policy_type
        cls.upd_sp_change = int(cls.autoscale_config.upd_sp_change)
        cls.lc_load_balancers = cls.autoscale_config.lc_load_balancers
        cls.sp_list = cls.autoscale_config.sp_list
        cls.wb_name = rand_name(cls.autoscale_config.wb_name)
        cls.interval_time = int(cls.autoscale_config.interval_time)
        cls.timeout = int(cls.autoscale_config.timeout)
Esempio n. 8
0
    def setUpClass(cls):
        super(BareMetalFixture, cls).setUpClass()
        cls.marshalling = MarshallingConfig()
        cls.bare_metal_endpoint = BareMetalEndpointConfig()

        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        cls.access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                       cls.user_config)

        # If authentication fails, halt
        if cls.access_data is None:
            cls.assertClassSetupFailure('Authentication failed.')

        bare_metal_service = cls.access_data.get_service(
            cls.bare_metal_endpoint.bare_metal_endpoint_name)
        url = bare_metal_service.get_endpoint(
            cls.bare_metal_endpoint.region).public_url

        # If a url override was provided, use that value instead
        if cls.bare_metal_endpoint.bare_metal_endpoint_url:
            url = cls.bare_metal_endpoint.bare_metal_endpoint_url

        client_args = {'url': url, 'auth_token': cls.access_data.token.id_,
                       'serialize_format': cls.marshalling.serializer,
                       'deserialize_format': cls.marshalling.deserializer}

        cls.chassis_client = ChassisClient(**client_args)
        cls.drivers_client = DriversClient(**client_args)
        cls.nodes_client = NodesClient(**client_args)
        cls.ports_client = PortsClient(**client_args)

        cls.resources = ResourcePool()
        cls.addClassCleanup(cls.resources.release)
Esempio n. 9
0
    def setUpClass(cls):
        super(ComputeAdminFixture, cls).setUpClass()

        # Setup admin client
        auth_config = ComputeAdminAuthConfig()
        user_config = ComputeAdminUserConfig()
        access_data = AuthProvider.get_access_data(auth_config,
                                                   user_config)
        admin_endpoint_config = ComputeAdminEndpointConfig()
        compute_service = access_data.get_service(
            admin_endpoint_config.compute_endpoint_name)
        url = compute_service.get_endpoint(
            admin_endpoint_config.region).public_url

        client_args = {'url': url, 'auth_token': access_data.token.id_,
                       'serialize_format': cls.marshalling.serializer,
                       'deserialize_format': cls.marshalling.deserializer}

        cls.admin_flavors_client = FlavorsClient(**client_args)
        cls.admin_servers_client = ServersClient(**client_args)
        cls.admin_images_client = ImagesClient(**client_args)
        cls.admin_hosts_client = HostsClient(**client_args)
        cls.admin_quotas_client = QuotasClient(**client_args)
        cls.admin_hypervisors_client = HypervisorsClient(**client_args)
        cls.admin_server_behaviors = ServerBehaviors(
            servers_client=cls.admin_servers_client,
            images_client=cls.images_client, servers_config=cls.servers_config,
            images_config=cls.images_config, flavors_config=cls.flavors_config)
        cls.admin_images_behaviors = ImageBehaviors(cls.admin_images_client,
                                                    cls.admin_servers_client,
                                                    cls.images_config)
        cls.admin_servers_client.add_exception_handler(ExceptionHandler())
Esempio n. 10
0
    def setUpClass(cls):
        super(ComputeAdminFixture, cls).setUpClass()

        # Setup admin client
        auth_config = ComputeAdminAuthConfig()
        user_config = ComputeAdminUserConfig()
        access_data = AuthProvider.get_access_data(auth_config,
                                                   user_config)
        admin_endpoint_config = ComputeAdminEndpointConfig()
        compute_service = access_data.get_service(
            admin_endpoint_config.compute_endpoint_name)
        url = compute_service.get_endpoint(
            admin_endpoint_config.region).public_url
        cls.admin_flavors_client = FlavorsClient(url, access_data.token.id_,
                                                 'json', 'json')
        cls.admin_servers_client = ServersClient(url, access_data.token.id_,
                                                 'json', 'json')
        cls.admin_server_behaviors = ServerBehaviors(cls.admin_servers_client,
                                                     cls.servers_config,
                                                     cls.images_config,
                                                     cls.flavors_config)
        cls.admin_images_client = ImagesClient(url, access_data.token.id_,
                                               'json', 'json')
        cls.admin_images_behaviors = ImageBehaviors(cls.admin_images_client,
                                                    cls.admin_servers_client,
                                                    cls.images_config)
        cls.admin_hosts_client = HostsClient(url, access_data.token.id_,
                                             'json', 'json')
        cls.admin_servers_client.add_exception_handler(ExceptionHandler())
Esempio n. 11
0
    def setUpClass(cls):
        super(ComputeAdminFixture, cls).setUpClass()

        # Setup admin client
        auth_config = ComputeAdminAuthConfig()
        user_config = ComputeAdminUserConfig()
        access_data = AuthProvider.get_access_data(auth_config,
                                                   user_config)
        admin_endpoint_config = ComputeAdminEndpointConfig()
        compute_service = access_data.get_service(
            admin_endpoint_config.compute_endpoint_name)
        url = compute_service.get_endpoint(
            admin_endpoint_config.region).public_url

        client_args = {'url': url, 'auth_token': access_data.token.id_,
                       'serialize_format': cls.marshalling.serializer,
                       'deserialize_format': cls.marshalling.deserializer}

        cls.admin_flavors_client = FlavorsClient(**client_args)
        cls.admin_servers_client = ServersClient(**client_args)
        cls.admin_images_client = ImagesClient(**client_args)
        cls.admin_hosts_client = HostsClient(**client_args)
        cls.admin_quotas_client = QuotasClient(**client_args)
        cls.admin_hypervisors_client = HypervisorsClient(**client_args)
        cls.admin_server_behaviors = ServerBehaviors(cls.admin_servers_client,
                                                     cls.servers_config,
                                                     cls.images_config,
                                                     cls.flavors_config)
        cls.admin_images_behaviors = ImageBehaviors(cls.admin_images_client,
                                                    cls.admin_servers_client,
                                                    cls.images_config)
        cls.admin_servers_client.add_exception_handler(ExceptionHandler())
Esempio n. 12
0
    def setUpClass(cls):
        super(ComputeFixture, cls).setUpClass()
        cls.flavors_config = FlavorsConfig()
        cls.images_config = ImagesConfig()
        cls.servers_config = ServersConfig()
        cls.compute_endpoint = ComputeEndpointConfig()
        cls.marshalling = MarshallingConfig()
        cls.config_drive_config = ConfigDriveConfig()

        cls.flavor_ref = cls.flavors_config.primary_flavor
        cls.flavor_ref_alt = cls.flavors_config.secondary_flavor
        cls.image_ref = cls.images_config.primary_image
        cls.image_ref_alt = cls.images_config.secondary_image
        cls.disk_path = cls.servers_config.instance_disk_path

        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                   cls.user_config)
        # If authentication fails, halt
        if access_data is None:
            cls.assertClassSetupFailure('Authentication failed.')

        compute_service = access_data.get_service(
            cls.compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            cls.compute_endpoint.region).public_url
        # If a url override was provided, use that value instead
        if cls.compute_endpoint.compute_endpoint_url:
            url = '{0}/{1}'.format(cls.compute_endpoint.compute_endpoint_url,
                                   cls.user_config.tenant_id)

        client_args = {'url': url, 'auth_token': access_data.token.id_,
                       'serialize_format': cls.marshalling.serializer,
                       'deserialize_format': cls.marshalling.deserializer}

        cls.flavors_client = FlavorsClient(**client_args)
        cls.servers_client = ServersClient(**client_args)
        cls.images_client = ImagesClient(**client_args)
        cls.keypairs_client = KeypairsClient(**client_args)
        cls.security_groups_client = SecurityGroupsClient(**client_args)
        cls.security_group_rule_client = SecurityGroupRulesClient(
            **client_args)
        cls.rescue_client = RescueClient(**client_args)
        cls.vnc_client = VncConsoleClient(**client_args)
        cls.console_output_client = ConsoleOutputClient(**client_args)
        cls.server_behaviors = ServerBehaviors(cls.servers_client,
                                               cls.servers_config,
                                               cls.images_config,
                                               cls.flavors_config)
        cls.image_behaviors = ImageBehaviors(cls.images_client,
                                             cls.servers_client,
                                             cls.images_config)
        cls.config_drive_behaviors = ConfigDriveBehaviors(cls.servers_client,
                                                          cls.servers_config,
                                                          cls.server_behaviors)
        cls.flavors_client.add_exception_handler(ExceptionHandler())
        cls.resources = ResourcePool()
Esempio n. 13
0
    def __init__(self, images_client, images_config):
        super(ImagesV1Behaviors, self).__init__()
        self.config = images_config
        self.client = images_client

        access_data = AuthProvider().get_access_data()
        self.tenants_client = TenantsAPI_Client(UserAuthConfig().auth_endpoint,
                                                access_data.token.id_, 'json',
                                                'json')
    def setUpClass(cls):
        super(TestFixedIPsMultiple, cls).setUpClass()
        network_name = 'network_{0}'.format(cls.NAMES_PREFIX)
        cls.network = cls.create_server_network(name=network_name, ipv4=True)
        cls.delete_networks.append(cls.network.id)
        keypair_name = 'key_{0}'.format(cls.NAMES_PREFIX)
        cls.keypair = cls.create_keypair(name=keypair_name)
        cls.delete_keypairs.append(cls.keypair.name)
        svr_name = 'svr_{0}'.format(cls.NAMES_PREFIX)
        network_ids = [
            cls.public_network_id, cls.service_network_id, cls.network.id
        ]
        cls.server = cls.create_test_server(name=svr_name,
                                            key_name=cls.keypair.name,
                                            network_ids=network_ids,
                                            active_server=False)
        cls.server_persona = ServerPersona(server=cls.server,
                                           pnet=True,
                                           snet=True,
                                           inet=True,
                                           pnet_fix_ipv4_count=1,
                                           snet_fix_ipv4_count=1,
                                           inet_fix_ipv4_count=1,
                                           network=cls.network,
                                           keypair=cls.keypair,
                                           ssh_username='******')
        server_ids = [cls.server_persona.server.id]
        cls.delete_servers.extend(server_ids)

        cls.pub_net_id = cls.public_network_id
        cls.pri_net_id = cls.service_network_id
        cls.iso_net_id = cls.network.id
        cls.initial_pub_ip = cls.server_persona.pnet_fix_ipv4
        cls.initial_pri_ip = cls.server_persona.snet_fix_ipv4
        cls.initial_iso_ip = cls.server_persona.inet_fix_ipv4
        # Initial IPv4 counts, update as needed if using a specific server
        cls.ini_ips_count = 1
        # Multiple fixed IPs to add
        cls.FIXED_IPS_TO_ADD = cls.net.config.multiple_fixed_ips_to_add

        admin_user = ComputeAdminUserConfig()
        compute_admin_endpoint = ComputeAdminEndpointConfig()
        auth_endpoint_config = ComputeAdminAuthConfig()
        access_data = AuthProvider.get_access_data(auth_endpoint_config,
                                                   admin_user)
        compute_service = access_data.get_service(
            compute_admin_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            compute_admin_endpoint.region).public_url
        cls.servers_client = ServersClient(url, access_data.token.id_, 'json',
                                           'json')

        cls.add_msg = ('Unable to add a {0} network fixed IP to server {1} '
                       'Response: {2}')
        cls.rem_msg = ('Unable to remove a {0} network fixed IP of server {1} '
                       'Response: {2}')
Esempio n. 15
0
def _set_up_clients():
    """
    Read the user creds from the configuration file in and constructs all the
    service clients.  If it can't authenticate, or it cannot construct the
    autoscale/server/lbaas clients, then it fails.

    The RCv3 client is not created if the account does not have access to RCv3
    or if RCv3 configuration parameters are not present or invalid.
    """
    user_config = UserConfig()
    access_data = AuthProvider.get_access_data(endpoint_config, user_config)

    if access_data is None:
        raise Exception(
            "Unable to authenticate against identity to get auth token and "
            "service catalog.")

    _autoscale_client = _make_client(
        access_data,
        autoscale_config.autoscale_endpoint_name,
        autoscale_config.region,
        AutoscalingAPIClient,
        "Autoscale")

    _server_client = _make_client(
        access_data,
        autoscale_config.server_endpoint_name,
        autoscale_config.server_region_override or autoscale_config.region,
        ServersClient,
        "Nova Compute")

    _lbaas_client = _make_client(
        access_data,
        autoscale_config.load_balancer_endpoint_name,
        autoscale_config.lbaas_region_override or autoscale_config.region,
        LbaasAPIClient,
        "Cloud Load Balancers")

    _rcv3_client = None
    if _rcv3_cloud_network and _rcv3_load_balancer_pool:
        _rcv3_client = _make_client(
            access_data,
            autoscale_config.rcv3_endpoint_name,
            autoscale_config.rcv3_region_override or autoscale_config.region,
            RackConnectV3APIClient,
            "RackConnect v3")
    else:
        print("Not enough test configuration for RCv3 provided. "
              "Will not run RCv3 tests.")

    if not all([x is not None for x in (_autoscale_client, _server_client,
                                        _lbaas_client)]):
        raise Exception(
            "Unable to instantiate all necessary clients.")

    return (_autoscale_client, _server_client, _lbaas_client, _rcv3_client)
Esempio n. 16
0
    def setUpClass(cls):
        super(ImagesFixture, cls).setUpClass()
        cls.marshalling = MarshallingConfig()
        cls.images_config = ImagesConfig()
        cls.primary_image = cls.images_config.primary_image

        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        cls.access_data = AuthProvider.get_access_data(cls.endpoint_config, cls.user_config)
        # If authentication fails, halt
        if cls.access_data is None:
            cls.assertClassSetupFailure("Authentication failed.")

        image_service = cls.access_data.get_service(cls.images_config.endpoint_name)
        url = image_service.get_endpoint(cls.images_config.region).public_url + "/v2"
        client_args = {
            "base_url": url,
            "auth_token": cls.access_data.token.id_,
            "serialize_format": cls.marshalling.serializer,
            "deserialize_format": cls.marshalling.deserializer,
        }
        cls.images_client = ImagesClient(**client_args)

        cls.alt_user_config = AltUserConfig()
        cls.alt_access_data = AuthProvider.get_access_data(cls.endpoint_config, cls.alt_user_config)

        # If authentication fails, halt
        if cls.alt_access_data is None:
            cls.assertClassSetupFailure("Authentication failed.")
        image_service = cls.alt_access_data.get_service(cls.images_config.endpoint_name)
        url = image_service.get_endpoint(cls.images_config.region).public_url + "/v2"
        client_args = {
            "base_url": url,
            "auth_token": cls.alt_access_data.token.id_,
            "serialize_format": cls.marshalling.serializer,
            "deserialize_format": cls.marshalling.deserializer,
        }
        cls.alt_images_client = ImagesClient(**client_args)
        cls.alt_tenant_id = cls.alt_access_data.token.tenant.id_
        cls.resources = ResourcePool()
        cls.addClassCleanup(cls.resources.release)
Esempio n. 17
0
def get_auth_token():
    '''
    * This method is to retrieve the User Auth Token from Identity
    * The credentials will be read from a config file
    * Inputs: None
    * Returns: the Auth Token ( a string of letters and numbers)
    '''
    end_config = UserAuthConfig()

    user_config = UserConfig()
    access_data = AuthProvider.get_access_data(end_config, user_config)

    return  access_data.token.id_
Esempio n. 18
0
    def setUpClass(cls):
        super(ImagesV2Fixture, cls).setUpClass()
        cls.config = ImagesConfig()
        cls.resources = ResourcePool()

        access_data = AuthProvider.get_access_data()

        cls.images_endpoint = '{base_url}/v2'.format(
            base_url=cls.config.base_url)

        cls.api_client = ImagesV2Client(cls.images_endpoint,
                                        access_data.token.id_,
                                        'json', 'json')
Esempio n. 19
0
    def setUpClass(cls):
        super(ComputeIntegrationFixture, cls).setUpClass()
        cls.flavors_config = FlavorsConfig()
        cls.images_config = ImagesConfig()
        cls.servers_config = ServersConfig()
        cls.compute_endpoint = ComputeEndpointConfig()
        cls.marshalling = MarshallingConfig()
        cls.security_groups_config = SecurityGroupsConfig()

        cls.flavor_ref = cls.flavors_config.primary_flavor

        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        cls.access_data = AuthProvider.get_access_data(cls.endpoint_config, cls.user_config)
        # If authentication fails, halt
        if cls.access_data is None:
            cls.assertClassSetupFailure("Authentication failed.")

        compute_service = cls.access_data.get_service(cls.compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(cls.compute_endpoint.region).public_url
        # If a url override was provided, use that value instead
        if cls.compute_endpoint.compute_endpoint_url:
            url = "{0}/{1}".format(cls.compute_endpoint.compute_endpoint_url, cls.user_config.tenant_id)

        client_args = {
            "url": url,
            "auth_token": cls.access_data.token.id_,
            "serialize_format": cls.marshalling.serializer,
            "deserialize_format": cls.marshalling.deserializer,
        }

        cls.flavors_client = FlavorsClient(**client_args)
        cls.servers_client = ServersClient(**client_args)
        cls.compute_images_client = ComputeImagesClient(**client_args)
        cls.keypairs_client = KeypairsClient(**client_args)
        cls.server_behaviors = ServerBehaviors(
            cls.servers_client,
            cls.compute_images_client,
            cls.servers_config,
            cls.images_config,
            cls.flavors_config,
            security_groups_config=cls.security_groups_config,
        )
        cls.image_behaviors = ImageBehaviors(cls.compute_images_client, cls.servers_client, cls.images_config)
        cls.config_drive_behaviors = ConfigDriveBehaviors(cls.servers_client, cls.servers_config, cls.server_behaviors)
        cls.resources = ResourcePool()
        cls.addClassCleanup(cls.resources.release)
Esempio n. 20
0
    def authenticate(cls, username=None, password=None):
        """ Should only be called from an instance of AuthComposite """
        if username and password:
            client = TokenAPI_Client(
                UserAuthConfig().auth_endpoint,
                serialize_format="json",
                deserialize_format="json")
            access_data = client.authenticate(
                username=username,
                password=password).entity
        else:
            access_data = AuthProvider.get_access_data()

        if access_data is None:
            raise AssertionError('Authentication failed in setup')

        return access_data
Esempio n. 21
0
    def authenticate(cls, username=None, password=None):
        """ Should only be called from an instance of AuthComposite """
        if username and password:
            from cloudcafe.identity.v2_0.tokens_api.client import \
                TokenAPI_Client
            client = TokenAPI_Client(UserAuthConfig().auth_endpoint,
                                     serialize_format="json",
                                     deserialize_format="json")
            access_data = client.authenticate(username=username,
                                              password=password).entity
        else:
            access_data = AuthProvider.get_access_data()

        if access_data is None:
            raise AssertionError('Authentication failed in setup')

        return access_data
Esempio n. 22
0
    def setUpClass(cls):
        super(ImagesV1Fixture, cls).setUpClass()
        access_data = AuthProvider().get_access_data()
        images_endpoint = '{base_url}/v1'.format(base_url=cls.config.base_url)

        cls.remote_image = cls.config.remote_image
        cls.http_image = cls.config.http_image

        cls.tenants_client = TenantsAPI_Client(UserAuthConfig().auth_endpoint,
                                               access_data.token.id_, 'json',
                                               'json')

        cls.api_client = ImagesV1Client(images_endpoint, access_data.token.id_,
                                        'json', 'json')
        cls.behaviors = ImagesV1Behaviors(cls.api_client, cls.config)
        cls.tenant_ids = TenantsBehaviors(
            cls.tenants_client).get_all_tenant_ids()
Esempio n. 23
0
    def generate_user_list(cls, account_list):
        """
        @summary: Generates list of users containing access_data, account
        types, behaviors, clients, and configurations
        """

        cls.ACCESS_DATA = "access_data"
        cls.BEHAVIOR = "behavior"
        cls.CLIENT = "client"
        cls.CONFIG = "config"
        user_list = dict()
        for user in account_list:
            user_list[user] = dict()
            user_list[user][cls.CONFIG] = UserConfig(section_name=user)
            user_list[user][cls.CONFIG].SECTION_NAME = user

            access_data = AuthProvider.get_access_data(
                cls.endpoint_config,
                user_config=user_list[user][cls.CONFIG])
            # If authentication fails, fail immediately
            if access_data is None:
                cls.assertClassSetupFailure('Authentication failed.')
            user_list[user][cls.ACCESS_DATA] = access_data

            images_service = access_data.get_service(
                cls.images_config.endpoint_name)
            images_url_check = images_service.get_endpoint(
                cls.images_config.region)
            # If endpoint validation fails, fail immediately
            if images_url_check is None:
                cls.assertClassSetupFailure('Endpoint validation failed')
            cls.url = (images_service.get_endpoint(
                cls.images_config.region).public_url)
            # If a url override was provided, use it instead
            if cls.images_config.override_url:
                cls.url = cls.images_config.override_url

            images_client = cls.generate_images_client(access_data)
            user_list[user][cls.CLIENT] = images_client

            images_behavior = ImagesBehaviors(images_client, cls.images_config)
            user_list[user][cls.BEHAVIOR] = images_behavior

        return user_list
Esempio n. 24
0
    def setUpClass(cls):
        """
        Perform actions that setup the necessary resources for testing.

        The following resources are created during this setup:
            - Creates an active server with metadata.
            - Creates an image with metadata and waits for active status.
        """
        super(AuthorizationTests, cls).setUpClass()
        cls.metadata = {
            'meta_key_1': 'meta_value_1',
            'meta_key_2': 'meta_value_2'
        }
        cls.server = cls.server_behaviors.create_active_server(
            metadata=cls.metadata).entity
        cls.resources.add(cls.server.id, cls.servers_client.delete_server)

        image_name = rand_name('testimage')
        cls.image_meta = {'user_key1': 'value1', 'user_key2': 'value2'}
        image_resp = cls.servers_client.create_image(cls.server.id, image_name,
                                                     cls.image_meta)
        assert image_resp.status_code == 202
        cls.image_id = cls.parse_image_id(image_resp)
        cls.image_behaviors.wait_for_image_status(cls.image_id,
                                                  NovaImageStatusTypes.ACTIVE)
        cls.resources.add(cls.image_id, cls.images_client.delete_image)

        secondary_user = ComputeAuthorizationConfig()
        compute_endpoint = ComputeEndpointConfig()
        auth_endpoint_config = UserAuthConfig()
        access_data = AuthProvider.get_access_data(auth_endpoint_config,
                                                   secondary_user)

        compute_service = access_data.get_service(
            compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(compute_endpoint.region).public_url

        cls.flavors_client = FlavorsClient(url, access_data.token.id_, 'json',
                                           'json')
        cls.servers_client = ServersClient(url, access_data.token.id_, 'json',
                                           'json')
        cls.images_client = ImagesClient(url, access_data.token.id_, 'json',
                                         'json')
        cls.flavors_client.add_exception_handler(ExceptionHandler())
Esempio n. 25
0
    def setUpClass(cls):
        super(ComputeFixture, cls).setUpClass()
        cls.flavors_config = FlavorsConfig()
        cls.images_config = ImagesConfig()
        cls.servers_config = ServersConfig()
        cls.compute_endpoint = ComputeEndpointConfig()

        cls.flavor_ref = cls.flavors_config.primary_flavor
        cls.flavor_ref_alt = cls.flavors_config.secondary_flavor
        cls.image_ref = cls.images_config.primary_image
        cls.image_ref_alt = cls.images_config.secondary_image
        cls.disk_path = cls.servers_config.instance_disk_path

        cls.endpoint_config = UserAuthConfig()
        user_config = UserConfig()
        access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                   user_config)

        compute_service = access_data.get_service(
            cls.compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            cls.compute_endpoint.region).public_url
        cls.flavors_client = FlavorsClient(url, access_data.token.id_, 'json',
                                           'json')
        cls.servers_client = ServersClient(url, access_data.token.id_, 'json',
                                           'json')
        cls.images_client = ImagesClient(url, access_data.token.id_, 'json',
                                         'json')
        cls.keypairs_client = KeypairsClient(url, access_data.token.id_,
                                             'json', 'json')
        cls.sec_groups_client = SecurityGroupsClient(url,
                                                     access_data.token.id_,
                                                     'json', 'json')
        cls.rescue_client = RescueClient(url, access_data.token.id_, 'json',
                                         'json')
        cls.server_behaviors = ServerBehaviors(cls.servers_client,
                                               cls.servers_config,
                                               cls.images_config,
                                               cls.flavors_config)
        cls.image_behaviors = ImageBehaviors(cls.images_client,
                                             cls.servers_client,
                                             cls.images_config)
        cls.flavors_client.add_exception_handler(ExceptionHandler())
        cls.resources = ResourcePool()
Esempio n. 26
0
    def setUpClass(cls):
        """
        Perform actions that setup the necessary resources for testing.

        The following resources are created during this setup:
            - Creates an active server with metadata.
            - Creates an image with metadata and waits for active status.
        """
        super(AuthorizationTests, cls).setUpClass()
        cls.metadata = {'meta_key_1': 'meta_value_1',
                        'meta_key_2': 'meta_value_2'}
        cls.server = cls.server_behaviors.create_active_server(
            metadata=cls.metadata).entity
        cls.resources.add(cls.server.id, cls.servers_client.delete_server)

        image_name = rand_name('testimage')
        cls.image_meta = {'user_key1': 'value1', 'user_key2': 'value2'}
        image_resp = cls.servers_client.create_image(cls.server.id,
                                                     image_name,
                                                     cls.image_meta)
        assert image_resp.status_code == 202
        cls.image_id = cls.parse_image_id(image_resp)
        cls.image_behaviors.wait_for_image_status(
            cls.image_id, NovaImageStatusTypes.ACTIVE)
        cls.resources.add(cls.image_id, cls.images_client.delete_image)

        secondary_user = ComputeAuthorizationConfig()
        compute_endpoint = ComputeEndpointConfig()
        auth_endpoint_config = UserAuthConfig()
        access_data = AuthProvider.get_access_data(
            auth_endpoint_config, secondary_user)

        compute_service = access_data.get_service(
            compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            compute_endpoint.region).public_url

        cls.flavors_client = FlavorsClient(
            url, access_data.token.id_, 'json', 'json')
        cls.servers_client = ServersClient(
            url, access_data.token.id_, 'json', 'json')
        cls.images_client = ImagesClient(
            url, access_data.token.id_, 'json', 'json')
        cls.flavors_client.add_exception_handler(ExceptionHandler())
Esempio n. 27
0
    def generate_user_list(cls, account_list):
        """
        @summary: Generates list of users containing access_data, account
        types, behaviors, clients, and configurations
        """

        cls.ACCESS_DATA = "access_data"
        cls.BEHAVIOR = "behavior"
        cls.CLIENT = "client"
        cls.CONFIG = "config"
        user_list = dict()
        for user in account_list:
            user_list[user] = dict()
            user_list[user][cls.CONFIG] = UserConfig(section_name=user)
            user_list[user][cls.CONFIG].SECTION_NAME = user

            access_data = AuthProvider.get_access_data(
                cls.endpoint_config, user_config=user_list[user][cls.CONFIG])
            # If authentication fails, fail immediately
            if access_data is None:
                cls.assertClassSetupFailure('Authentication failed.')
            user_list[user][cls.ACCESS_DATA] = access_data

            images_service = access_data.get_service(
                cls.images_config.endpoint_name)
            images_url_check = images_service.get_endpoint(
                cls.images_config.region)
            # If endpoint validation fails, fail immediately
            if images_url_check is None:
                cls.assertClassSetupFailure('Endpoint validation failed')
            cls.url = (images_service.get_endpoint(
                cls.images_config.region).public_url)
            # If a url override was provided, use it instead
            if cls.images_config.override_url:
                cls.url = cls.images_config.override_url

            images_client = cls.generate_images_client(access_data)
            user_list[user][cls.CLIENT] = images_client

            images_behavior = ImagesBehaviors(images_client, cls.images_config)
            user_list[user][cls.BEHAVIOR] = images_behavior

        return user_list
Esempio n. 28
0
    def setUpClass(cls):
        super(ComputeFixture, cls).setUpClass()
        cls.flavors_config = FlavorsConfig()
        cls.images_config = ImagesConfig()
        cls.servers_config = ServersConfig()
        cls.compute_endpoint = ComputeEndpointConfig()

        cls.flavor_ref = cls.flavors_config.primary_flavor
        cls.flavor_ref_alt = cls.flavors_config.secondary_flavor
        cls.image_ref = cls.images_config.primary_image
        cls.image_ref_alt = cls.images_config.secondary_image
        cls.disk_path = cls.servers_config.instance_disk_path

        cls.endpoint_config = UserAuthConfig()
        user_config = UserConfig()
        access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                   user_config)

        compute_service = access_data.get_service(
            cls.compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            cls.compute_endpoint.region).public_url
        cls.flavors_client = FlavorsClient(url, access_data.token.id_,
                                           'json', 'json')
        cls.servers_client = ServersClient(url, access_data.token.id_,
                                           'json', 'json')
        cls.images_client = ImagesClient(url, access_data.token.id_,
                                         'json', 'json')
        cls.keypairs_client = KeypairsClient(url, access_data.token.id_,
                                             'json', 'json')
        cls.sec_groups_client = SecurityGroupsClient(
            url, access_data.token.id_, 'json', 'json')
        cls.rescue_client = RescueClient(url, access_data.token.id_,
                                         'json', 'json')
        cls.server_behaviors = ServerBehaviors(cls.servers_client,
                                               cls.servers_config,
                                               cls.images_config,
                                               cls.flavors_config)
        cls.image_behaviors = ImageBehaviors(cls.images_client,
                                             cls.servers_client,
                                             cls.images_config)
        cls.flavors_client.add_exception_handler(ExceptionHandler())
        cls.resources = ResourcePool()
Esempio n. 29
0
    def setUpClass(cls):
        super(BareMetalFixture, cls).setUpClass()
        cls.marshalling = MarshallingConfig()
        cls.bare_metal_endpoint = BareMetalEndpointConfig()

        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        cls.access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                       cls.user_config)

        # If authentication fails, halt
        if cls.access_data is None:
            cls.assertClassSetupFailure('Authentication failed.')

        bare_metal_service = cls.access_data.get_service(
            cls.bare_metal_endpoint.bare_metal_endpoint_name)
        url = bare_metal_service.get_endpoint(
            cls.bare_metal_endpoint.region).public_url

        # If a url override was provided, use that value instead
        if cls.bare_metal_endpoint.bare_metal_endpoint_url:
            url = cls.bare_metal_endpoint.bare_metal_endpoint_url

        client_args = {
            'url': url,
            'auth_token': cls.access_data.token.id_,
            'serialize_format': cls.marshalling.serializer,
            'deserialize_format': cls.marshalling.deserializer
        }

        cls.chassis_client = ChassisClient(**client_args)
        cls.drivers_client = DriversClient(**client_args)
        cls.nodes_client = NodesClient(**client_args)
        cls.ports_client = PortsClient(**client_args)

        cls.resources = ResourcePool()
        cls.addClassCleanup(cls.resources.release)
Esempio n. 30
0
    def setUpClass(cls):
        """
        Initialize autoscale configs, behaviors and client
        """
        super(AutoscaleFixture, cls).setUpClass()
        cls.resources = ResourcePool()
        cls.autoscale_config = AutoscaleConfig()
        cls.endpoint_config = UserAuthConfig()
        user_config = UserConfig()
        access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                   user_config)
        server_service = access_data.get_service(
            cls.autoscale_config.server_endpoint_name)
        server_url = server_service.get_endpoint(
            cls.autoscale_config.region).public_url

        cls.tenant_id = cls.autoscale_config.tenant_id
        cls.otter_endpoint = cls.autoscale_config.server_endpoint

        env = os.environ['OSTNG_CONFIG_FILE']
        if ('prod.ord' in env.lower()) or ('prod.dfw' in env.lower()):
            autoscale_service = access_data.get_service(
                cls.autoscale_config.autoscale_endpoint_name)
            cls.url = autoscale_service.get_endpoint(
                cls.autoscale_config.region).public_url
        else:
            cls.url = str(cls.otter_endpoint) + '/' + str(cls.tenant_id)

        cls.autoscale_client = AutoscalingAPIClient(
            cls.url, access_data.token.id_,
            'json', 'json')
        cls.server_client = ServersClient(
            server_url, access_data.token.id_,
            'json', 'json')
        cls.autoscale_behaviors = AutoscaleBehaviors(cls.autoscale_config,
                                                     cls.autoscale_client)
        cls.gc_name = cls.autoscale_config.gc_name
        cls.gc_cooldown = int(cls.autoscale_config.gc_cooldown)
        cls.gc_min_entities = int(cls.autoscale_config.gc_min_entities)
        cls.gc_min_entities_alt = int(cls.autoscale_config.gc_min_entities_alt)
        cls.gc_max_entities = int(cls.autoscale_config.gc_max_entities)
        cls.lc_name = cls.autoscale_config.lc_name
        cls.lc_flavor_ref = cls.autoscale_config.lc_flavor_ref
        cls.lc_image_ref = cls.autoscale_config.lc_image_ref
        cls.lc_image_ref_alt = cls.autoscale_config.lc_image_ref_alt
        cls.sp_name = rand_name(cls.autoscale_config.sp_name)
        cls.sp_cooldown = int(cls.autoscale_config.sp_cooldown)
        cls.sp_change = int(cls.autoscale_config.sp_change)
        cls.sp_change_percent = int(cls.autoscale_config.sp_change_percent)
        cls.sp_desired_capacity = int(cls.autoscale_config.sp_desired_capacity)
        cls.sp_policy_type = cls.autoscale_config.sp_policy_type
        cls.upd_sp_change = int(cls.autoscale_config.upd_sp_change)
        cls.lc_load_balancers = cls.autoscale_config.lc_load_balancers
        cls.sp_list = cls.autoscale_config.sp_list
        cls.wb_name = rand_name(cls.autoscale_config.wb_name)
        cls.interval_time = int(cls.autoscale_config.interval_time)
        cls.timeout = int(cls.autoscale_config.timeout)
        cls.scheduler_interval = OtterConstants.SCHEDULER_INTERVAL
        cls.scheduler_batch = OtterConstants.SCHEDULER_BATCH
        cls.max_maxentities = OtterConstants.MAX_MAXENTITIES
        cls.max_cooldown = OtterConstants.MAX_COOLDOWN
Esempio n. 31
0
    def setUpClass(cls):
        super(ImagesIntegrationFixture, cls).setUpClass()
        cls.object_storage_client = cls.client
        cls.object_storage_behaviors = cls.behaviors

        # Work around to create compute/obj storage additional user composites
        auth_endpoint_config = UserAuthConfig()
        compute_endpoint = ComputeEndpointConfig()
        images_config = ImagesConfig()
        flavors_config = FlavorsConfig()
        marshalling_config = MarshallingConfig()
        object_storage_config = ObjectStorageConfig()
        object_storage_api_config = ObjectStorageAPIConfig()
        servers_config = ServersConfig()
        user_config_alt_one = AltOneUserConfig()

        access_data_alt_one = AuthProvider.get_access_data(
            auth_endpoint_config, user_config_alt_one)

        # Create compute clients and behaviors for alt_one user
        compute_service_alt_one = access_data_alt_one.get_service(
            compute_endpoint.compute_endpoint_name)
        compute_url_check_alt_one = compute_service_alt_one.get_endpoint(
            compute_endpoint.region)
        # If compute endpoint validation fails, fail immediately
        if compute_url_check_alt_one is None:
            cls.assertClassSetupFailure('Compute endpoint validation failed')
        compute_url_alt_one = compute_service_alt_one.get_endpoint(
            compute_endpoint.region).public_url

        cls.compute_alt_one_images_client = ComputeImagesClient(
            compute_url_alt_one, access_data_alt_one.token.id_,
            marshalling_config.serializer, marshalling_config.deserializer)

        cls.compute_alt_one_servers_client = ServersClient(
            compute_url_alt_one, access_data_alt_one.token.id_,
            marshalling_config.serializer, marshalling_config.deserializer)

        cls.compute_alt_one_images_behaviors = ComputeImageBehaviors(
            images_client=cls.compute_alt_one_images_client,
            servers_client=cls.compute_alt_one_servers_client,
            config=images_config)

        cls.compute_alt_one_servers_behaviors = ServerBehaviors(
            servers_client=cls.compute_alt_one_servers_client,
            images_client=cls.compute_alt_one_images_client,
            servers_config=servers_config, images_config=images_config,
            flavors_config=flavors_config)

        # Create object storage client and behaviors for alt_one user
        object_storage_service_alt_one = access_data_alt_one.get_service(
            object_storage_config.identity_service_name)
        object_storage_url_check_alt_one = (
            object_storage_service_alt_one.get_endpoint(
                object_storage_config.region))
        # If endpoint validation fails, fail immediately
        if object_storage_url_check_alt_one is None:
            cls.assertClassSetupFailure('Endpoint validation failed')
        storage_url_alt_one = object_storage_service_alt_one.get_endpoint(
            object_storage_config.region).public_url

        cls.object_storage_alt_one_client = ObjectStorageAPIClient(
            storage_url_alt_one, access_data_alt_one.token.id_)

        cls.object_storage_alt_one_behaviors = ObjectStorageAPI_Behaviors(
            cls.object_storage_alt_one_client, object_storage_api_config)

        # Needed in order to allow assertions on exceptions
        cls.compute.flavors.client.delete_exception_handler(
            cls.compute_exception_handler)
Esempio n. 32
0
    def setUpClass(cls):
        super(ImagesIntegrationFixture, cls).setUpClass()
        cls.object_storage_client = cls.client
        cls.object_storage_behaviors = cls.behaviors

        # Work around to create compute/obj storage additional user composites
        auth_endpoint_config = UserAuthConfig()
        compute_endpoint = ComputeEndpointConfig()
        images_config = ImagesConfig()
        flavors_config = FlavorsConfig()
        marshalling_config = MarshallingConfig()
        object_storage_config = ObjectStorageConfig()
        object_storage_api_config = ObjectStorageAPIConfig()
        servers_config = ServersConfig()
        user_config_alt_one = AltOneUserConfig()

        access_data_alt_one = AuthProvider.get_access_data(
            auth_endpoint_config, user_config_alt_one)

        # Create compute clients and behaviors for alt_one user
        compute_service_alt_one = access_data_alt_one.get_service(
            compute_endpoint.compute_endpoint_name)
        compute_url_check_alt_one = compute_service_alt_one.get_endpoint(
            compute_endpoint.region)
        # If compute endpoint validation fails, fail immediately
        if compute_url_check_alt_one is None:
            cls.assertClassSetupFailure('Compute endpoint validation failed')
        compute_url_alt_one = compute_service_alt_one.get_endpoint(
            compute_endpoint.region).public_url

        cls.compute_alt_one_images_client = ComputeImagesClient(
            compute_url_alt_one, access_data_alt_one.token.id_,
            marshalling_config.serializer, marshalling_config.deserializer)

        cls.compute_alt_one_servers_client = ServersClient(
            compute_url_alt_one, access_data_alt_one.token.id_,
            marshalling_config.serializer, marshalling_config.deserializer)

        cls.compute_alt_one_images_behaviors = ComputeImageBehaviors(
            images_client=cls.compute_alt_one_images_client,
            servers_client=cls.compute_alt_one_servers_client,
            config=images_config)

        cls.compute_alt_one_servers_behaviors = ServerBehaviors(
            servers_client=cls.compute_alt_one_servers_client,
            images_client=cls.compute_alt_one_images_client,
            servers_config=servers_config, images_config=images_config,
            flavors_config=flavors_config)

        # Create object storage client and behaviors for alt_one user
        object_storage_service_alt_one = access_data_alt_one.get_service(
            object_storage_config.identity_service_name)
        object_storage_url_check_alt_one = (
            object_storage_service_alt_one.get_endpoint(
                object_storage_config.region))
        # If endpoint validation fails, fail immediately
        if object_storage_url_check_alt_one is None:
            cls.assertClassSetupFailure('Endpoint validation failed')
        storage_url_alt_one = object_storage_service_alt_one.get_endpoint(
            object_storage_config.region).public_url

        cls.object_storage_alt_one_client = ObjectStorageAPIClient(
            storage_url_alt_one, access_data_alt_one.token.id_)

        cls.object_storage_alt_one_behaviors = ObjectStorageAPI_Behaviors(
            cls.object_storage_alt_one_client, object_storage_api_config)

        # Needed in order to allow assertions on exceptions
        cls.compute.flavors.client.delete_exception_handler(
            cls.compute_exception_handler)
Esempio n. 33
0
    def setUpClass(cls):
        super(ComputeFixture, cls).setUpClass()
        cls.flavors_config = FlavorsConfig()
        cls.images_config = ImagesConfig()
        cls.servers_config = ServersConfig()
        cls.compute_endpoint = ComputeEndpointConfig()
        cls.marshalling = MarshallingConfig()
        cls.config_drive_config = ConfigDriveConfig()
        cls.cloud_init_config = CloudInitConfig()

        cls.flavor_ref = cls.flavors_config.primary_flavor
        cls.flavor_ref_alt = cls.flavors_config.secondary_flavor
        cls.image_ref = cls.images_config.primary_image
        cls.image_ref_alt = cls.images_config.secondary_image
        cls.disk_path = cls.servers_config.instance_disk_path
        cls.split_ephemeral_disk_enabled = \
            cls.servers_config.split_ephemeral_disk_enabled
        cls.ephemeral_disk_max_size = \
            cls.servers_config.ephemeral_disk_max_size
        cls.disk_format_type = cls.servers_config.disk_format_type
        cls.expected_networks = cls.servers_config.expected_networks
        cls.file_injection_enabled = \
            cls.servers_config.personality_file_injection_enabled

        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        cls.access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                       cls.user_config)
        # If authentication fails, halt
        if cls.access_data is None:
            cls.assertClassSetupFailure('Authentication failed.')

        compute_service = cls.access_data.get_service(
            cls.compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            cls.compute_endpoint.region).public_url
        # If a url override was provided, use that value instead
        if cls.compute_endpoint.compute_endpoint_url:
            url = '{0}/{1}'.format(cls.compute_endpoint.compute_endpoint_url,
                                   cls.user_config.tenant_id)

        client_args = {'url': url, 'auth_token': cls.access_data.token.id_,
                       'serialize_format': cls.marshalling.serializer,
                       'deserialize_format': cls.marshalling.deserializer}

        cls.flavors_client = FlavorsClient(**client_args)
        cls.servers_client = ServersClient(**client_args)
        cls.boot_from_volume_client = VolumesBootClient(**client_args)
        cls.images_client = ImagesClient(**client_args)
        cls.keypairs_client = KeypairsClient(**client_args)
        cls.security_groups_client = SecurityGroupsClient(**client_args)
        cls.security_group_rule_client = SecurityGroupRulesClient(
            **client_args)
        cls.volume_attachments_client = VolumeAttachmentsAPIClient(
            url=url, auth_token=cls.access_data.token.id_,
            serialize_format=cls.marshalling.serializer,
            deserialize_format=cls.marshalling.deserializer)
        cls.rescue_client = RescueClient(**client_args)
        cls.vnc_client = VncConsoleClient(**client_args)
        cls.console_output_client = ConsoleOutputClient(**client_args)
        cls.limits_client = LimitsClient(**client_args)
        cls.server_behaviors = ServerBehaviors(
            servers_client=cls.servers_client,
            images_client=cls.images_client,
            servers_config=cls.servers_config,
            images_config=cls.images_config,
            flavors_config=cls.flavors_config)
        cls.volume_server_behaviors = VolumeServerBehaviors(
            servers_client=cls.servers_client,
            images_client=cls.images_client,
            servers_config=cls.servers_config,
            images_config=cls.images_config,
            flavors_config=cls.flavors_config,
            server_behaviors=cls.server_behaviors,
            boot_from_volume_client=cls.boot_from_volume_client)
        cls.image_behaviors = ImageBehaviors(cls.images_client,
                                             cls.servers_client,
                                             cls.images_config)
        cls.config_drive_behaviors = ConfigDriveBehaviors(cls.servers_client,
                                                          cls.servers_config,
                                                          cls.server_behaviors)
        cls.flavors_client.add_exception_handler(ExceptionHandler())
        cls.resources = ResourcePool()
        cls.addClassCleanup(cls.resources.release)
class TestFixedIPsConnectivity(NetworkingComputeFixture, ScenarioMixin):
    """
    Testing connectivity between servers by adding fixed ips to existing
    servers.

    """
    NAMES_PREFIX = 'fixed_ips_connectivity'
    PRIVATE_KEY_PATH = '/root/pkey'
    MAX_RETRIES = 5

    admin_user = ComputeAdminUserConfig()
    compute_admin_endpoint = ComputeAdminEndpointConfig()
    auth_endpoint_config = ComputeAdminAuthConfig()
    access_data = AuthProvider.get_access_data(auth_endpoint_config,
                                               admin_user)
    compute_service = access_data.get_service(
        compute_admin_endpoint.compute_endpoint_name)
    url = compute_service.get_endpoint(
        compute_admin_endpoint.region).public_url
    servers_client = ServersClient(url, access_data.token.id_, 'json', 'json')

    SSH_COMMAND = ('ssh -o UserKnownHostsFile=/dev/null '
                   '-o StrictHostKeyChecking=no -o ConnectTimeout=60 '
                   '-i {private_key_path} {user}@{ip_address}')

    ssh_msg = ('Failed remote ssh connection from ' 'server {0} to server {1}')

    @classmethod
    def setUpClass(cls):
        super(TestFixedIPsConnectivity, cls).setUpClass()
        network_name = 'network_{0}'.format(cls.NAMES_PREFIX)
        cls.network = cls.create_server_network(name=network_name, ipv4=True)
        cls.delete_networks.append(cls.network.id)
        keypair_name = 'key_{0}'.format(cls.NAMES_PREFIX)
        cls.keypair = cls.create_keypair(name=keypair_name)
        cls.delete_keypairs.append(cls.keypair.name)
        svr_name_1 = 'svr_1_{0}'.format(cls.NAMES_PREFIX)
        svr_name_2 = 'svr_2_{0}'.format(cls.NAMES_PREFIX)
        network_ids = [
            cls.public_network_id, cls.service_network_id, cls.network.id
        ]
        cls.server1 = cls.create_test_server(name=svr_name_1,
                                             key_name=cls.keypair.name,
                                             network_ids=network_ids,
                                             active_server=False)
        cls.server2 = cls.create_test_server(name=svr_name_2,
                                             key_name=cls.keypair.name,
                                             network_ids=network_ids,
                                             active_server=False)
        cls.servers = [cls.server1, cls.server2]

        cls.FIXED_IPS_TO_ADD = cls.net.config.fixed_ips_to_add
        cls.PNET_FIX_IPv4_COUNT = cls.FIXED_IPS_TO_ADD + 1
        cls.SNET_FIX_IPv4_COUNT = cls.FIXED_IPS_TO_ADD + 1
        cls.INET_FIX_IPv4_COUNT = cls.FIXED_IPS_TO_ADD + 1
        cls.TOTAL_INITIAL_IPS_SERVER = 3
        cls.TOTAL_NETWORKS_ATTACHED_TO_SERVER = 3
        cls.TOTAL_IPS_SERVER = cls.TOTAL_INITIAL_IPS_SERVER + \
            (cls.FIXED_IPS_TO_ADD * cls.TOTAL_NETWORKS_ATTACHED_TO_SERVER)
        # Add fixed IPs to servers
        for server in cls.servers:
            cls.add_fixed_ips_network(server,
                                      cls.public_network_id,
                                      number_fixed_ips=cls.FIXED_IPS_TO_ADD)
            cls.add_fixed_ips_network(server,
                                      cls.service_network_id,
                                      number_fixed_ips=cls.FIXED_IPS_TO_ADD)
            cls.add_fixed_ips_network(server,
                                      cls.network.id,
                                      number_fixed_ips=cls.FIXED_IPS_TO_ADD)

        cls.server_persona1 = ServerPersona(
            server=cls.server1,
            pnet=True,
            snet=True,
            inet=True,
            pnet_fix_ipv4_count=cls.PNET_FIX_IPv4_COUNT,
            snet_fix_ipv4_count=cls.SNET_FIX_IPv4_COUNT,
            inet_fix_ipv4_count=cls.INET_FIX_IPv4_COUNT,
            network=cls.network,
            keypair=cls.keypair,
            ssh_username='******')
        cls.server_persona2 = ServerPersona(
            server=cls.server2,
            pnet=True,
            snet=True,
            inet=True,
            pnet_fix_ipv4_count=cls.PNET_FIX_IPv4_COUNT,
            snet_fix_ipv4_count=cls.SNET_FIX_IPv4_COUNT,
            inet_fix_ipv4_count=cls.INET_FIX_IPv4_COUNT,
            network=cls.network,
            keypair=cls.keypair,
            ssh_username='******')
        server_ids = [
            cls.server_persona1.server.id, cls.server_persona2.server.id
        ]
        cls.delete_servers.extend(server_ids)

        cls._transfer_private_key_to_vm(
            cls.server_persona1.remote_client.ssh_client,
            cls.keypair.private_key, cls.PRIVATE_KEY_PATH)
        cls._transfer_private_key_to_vm(
            cls.server_persona2.remote_client.ssh_client,
            cls.keypair.private_key, cls.PRIVATE_KEY_PATH)

    @tags('admin', 'positive')
    def test_server_ifconfig(self):
        """Testing ifconfig on servers"""
        servers = [self.server_persona1, self.server_persona2]
        for server in servers:
            ips = []
            ips.extend(server.pnet_fix_ipv4)
            ips.extend(server.snet_fix_ipv4)
            ips.extend(server.inet_fix_ipv4)
            rm_client = server.remote_client
            ifconfig_ips = []
            stdout = None
            retry_count = 0
            while stdout is None or len(ifconfig_ips) != self.TOTAL_IPS_SERVER:
                del ifconfig_ips[:]
                if retry_count < self.MAX_RETRIES:
                    ifconfig_output = rm_client.ssh_client.\
                        execute_shell_command("hostname -I")
                    stdout = ifconfig_output.stdout
                    pattern = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
                    matches = pattern.finditer(stdout)
                    for match in matches:
                        ifconfig_ips.append(match.group())
                if len(ifconfig_ips) == self.TOTAL_IPS_SERVER or \
                        retry_count == self.MAX_RETRIES:
                    break
                retry_count += 1
            server_ip_not_found = False
            for ip in ips:
                if ip not in ifconfig_ips:
                    server_ip_not_found = True
                    break
            self.assertFalse(server_ip_not_found,
                             msg="server {} ip {} not found in output of "
                             "ifconfig {}".format(server, ip, ifconfig_ips))

    @tags('admin', 'positive')
    def test_public_ping(self):
        """Testing ping on servers with public network"""
        msg_err = 'Public ping to IP address {0} - FAILED'
        msg_ok = 'Public ping to IP address {0} - OK'

        pub_ipv4_addr = []
        pub_ipv4_addr.extend(self.server_persona1.pnet_fix_ipv4)
        pub_ipv4_addr.extend(self.server_persona2.pnet_fix_ipv4)
        all_pub_ips_ping_result = []
        failure_flag = False
        for ip_addr in pub_ipv4_addr:
            ip_addr_reachable = PingClient.ping(ip_addr, 4)
            if ip_addr_reachable:
                all_pub_ips_ping_result.append(msg_ok.format(ip_addr))
            else:
                all_pub_ips_ping_result.append(msg_err.format(ip_addr))
                failure_flag = True
        msg = 'Got connectivity failures. Ping Results: {0}'

        # Fail the test if any ping failure is found
        self.assertFalse(failure_flag, msg.format(all_pub_ips_ping_result))

    @tags('admin', 'positive')
    def test_remote_public_ping(self):
        """Testing public network remote ping on servers"""
        self._test_remote_ping(port_type='pnet')

    @tags('admin', 'positive')
    def test_remote_private_ping(self):
        """Testing private network remote ping on servers"""
        self._test_remote_ping(port_type='snet')

    @tags('admin', 'positive')
    def test_remote_isolated_ping(self):
        """Testing isolated network remote ping on servers"""
        self._test_remote_ping(port_type='inet')

    def _test_remote_ping(self, port_type):
        """Testing remote ping on servers"""
        conn = Connectivity(self.server_persona2, self.server_persona1)
        icmp_basic = dict(port_type=port_type, protocol='icmp', ip_version=4)
        rp = conn.verify_personas_conn(**icmp_basic)
        result = rp[0]
        ping_result = result['connection']
        self.assertTrue(ping_result, rp)

    @tags('admin', 'positive')
    def test_remote_public_ssh(self):
        """Testing Public remote ssh on servers"""
        self._test_remote_ssh(self.server_persona1.pnet_fix_ipv4[0])

    @tags('admin', 'positive')
    def test_remote_private_ssh(self):
        """Testing ServiceNet remote ssh on servers"""
        self._test_remote_ssh(self.server_persona1.snet_fix_ipv4[0])

    @tags('admin', 'positive')
    def test_remote_isolated_ssh(self):
        """Testing isolated network A remote ssh on servers"""
        self._test_remote_ssh(self.server_persona1.inet_fix_ipv4[0])

    def _test_remote_ssh(self, target_ip_addr):
        """Testing remote ssh on servers"""
        rc2 = self.server_persona2.remote_client
        ssh_cmd = self.SSH_COMMAND.format(
            private_key_path=self.PRIVATE_KEY_PATH,
            user=self.server_persona1.ssh_username,
            ip_address=target_ip_addr)
        stdout = None
        ssh_connection_established = False
        retry_count = 0
        while stdout is None or not stdout.endswith('# '):
            if retry_count < self.MAX_RETRIES:
                output = rc2.ssh_client.execute_shell_command(ssh_cmd)
                stdout = output.stdout
            retry_count += 1
            if retry_count == self.MAX_RETRIES:
                break
        if stdout.endswith('# '):
            ssh_connection_established = True
        self.assertTrue(
            ssh_connection_established,
            self.ssh_msg.format(self.server_persona2.pnet_fix_ipv4[0],
                                target_ip_addr))

    @classmethod
    def add_fixed_ips_network(cls, server, network, number_fixed_ips):
        # Add fixed IP's to server
        for _ in range(number_fixed_ips):
            cls.servers_client.add_fixed_ip(server.id, network)
Esempio n. 35
0
    def setUpClass(cls):
        """
        Initialize autoscale configs, behaviors and client
        """
        super(AutoscaleFixture, cls).setUpClass()
        cls.resources = ResourcePool()
        cls.autoscale_config = AutoscaleConfig()
        cls.endpoint_config = UserAuthConfig()
        user_config = UserConfig()
        access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                   user_config)
        server_service = access_data.get_service(
            cls.autoscale_config.server_endpoint_name)
        load_balancer_service = access_data.get_service(
            cls.autoscale_config.load_balancer_endpoint_name)
        server_url = server_service.get_endpoint(
            cls.autoscale_config.region).public_url
        lbaas_url = load_balancer_service.get_endpoint(
            cls.autoscale_config.region).public_url

        cls.tenant_id = cls.autoscale_config.tenant_id

        env = os.environ['OSTNG_CONFIG_FILE']
        if ('preprod' in env.lower()) or ('dev' in env.lower()):
            cls.url = str(cls.autoscale_config.server_endpoint) + '/' + str(
                cls.tenant_id)
        else:
            autoscale_service = access_data.get_service(
                cls.autoscale_config.autoscale_endpoint_name)
            cls.url = autoscale_service.get_endpoint(
                cls.autoscale_config.region).public_url

        cls.autoscale_client = AutoscalingAPIClient(cls.url,
                                                    access_data.token.id_,
                                                    'json', 'json')
        cls.server_client = ServersClient(server_url, access_data.token.id_,
                                          'json', 'json')
        cls.lbaas_client = LbaasAPIClient(lbaas_url, access_data.token.id_,
                                          'json', 'json')
        cls.autoscale_behaviors = AutoscaleBehaviors(cls.autoscale_config,
                                                     cls.autoscale_client)
        cls.gc_name = cls.autoscale_config.gc_name
        cls.gc_cooldown = int(cls.autoscale_config.gc_cooldown)
        cls.gc_min_entities = int(cls.autoscale_config.gc_min_entities)
        cls.gc_min_entities_alt = int(cls.autoscale_config.gc_min_entities_alt)
        cls.gc_max_entities = int(cls.autoscale_config.gc_max_entities)
        cls.lc_name = cls.autoscale_config.lc_name
        cls.lc_flavor_ref = cls.autoscale_config.lc_flavor_ref
        cls.lc_image_ref = cls.autoscale_config.lc_image_ref
        cls.lc_image_ref_alt = cls.autoscale_config.lc_image_ref_alt
        cls.sp_name = rand_name(cls.autoscale_config.sp_name)
        cls.sp_cooldown = int(cls.autoscale_config.sp_cooldown)
        cls.sp_change = int(cls.autoscale_config.sp_change)
        cls.sp_change_percent = int(cls.autoscale_config.sp_change_percent)
        cls.sp_desired_capacity = int(cls.autoscale_config.sp_desired_capacity)
        cls.sp_policy_type = cls.autoscale_config.sp_policy_type
        cls.upd_sp_change = int(cls.autoscale_config.upd_sp_change)
        cls.lc_load_balancers = cls.autoscale_config.lc_load_balancers
        cls.sp_list = cls.autoscale_config.sp_list
        cls.wb_name = rand_name(cls.autoscale_config.wb_name)
        cls.load_balancer_1 = int(cls.autoscale_config.load_balancer_1)
        cls.load_balancer_2 = int(cls.autoscale_config.load_balancer_2)
        cls.load_balancer_3 = int(cls.autoscale_config.load_balancer_3)
        cls.lb_other_region = int(cls.autoscale_config.lb_other_region)
        cls.interval_time = int(cls.autoscale_config.interval_time)
        cls.timeout = int(cls.autoscale_config.timeout)
        cls.scheduler_interval = OtterConstants.SCHEDULER_INTERVAL
        cls.scheduler_batch = OtterConstants.SCHEDULER_BATCH
        cls.max_maxentities = OtterConstants.MAX_MAXENTITIES
        cls.max_cooldown = OtterConstants.MAX_COOLDOWN
        cls.max_groups = OtterConstants.MAX_GROUPS
        cls.max_policies = OtterConstants.MAX_POLICIES
        cls.max_webhooks = OtterConstants.MAX_WEBHOOKS
        cls.limit_value_all = OtterConstants.LIMIT_VALUE_ALL
        cls.limit_unit_all = OtterConstants.LIMIT_UNIT_ALL
        cls.limit_value_webhook = OtterConstants.LIMIT_VALUE_WEBHOOK
        cls.limit_unit_webhook = OtterConstants.LIMIT_UNIT_WEBHOOK
        cls.non_autoscale_username = cls.autoscale_config.non_autoscale_username
        cls.non_autoscale_password = cls.autoscale_config.non_autoscale_password
        cls.non_autoscale_tenant = cls.autoscale_config.non_autoscale_tenant
Esempio n. 36
0
    def setUpClass(cls):
        super(ImagesFixture, cls).setUpClass()
        cls.images_config = ImagesConfig()
        cls.marshalling = MarshallingConfig()
        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        cls.alt_user_config = AltUserConfig()
        cls.third_user_config = ThirdUserConfig()
        cls.resources = ResourcePool()
        cls.serialize_format = cls.marshalling.serializer
        cls.deserialize_format = cls.marshalling.deserializer

        cls.access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                       cls.user_config)
        # If authentication fails, fail immediately
        if cls.access_data is None:
            cls.assertClassSetupFailure('Authentication failed')

        cls.alt_access_data = AuthProvider.get_access_data(
            cls.endpoint_config, cls.alt_user_config)
        # If authentication fails, fail immediately
        if cls.alt_access_data is None:
            cls.assertClassSetupFailure('Authentication failed')
        cls.third_access_data = AuthProvider.get_access_data(
            cls.endpoint_config, cls.third_user_config)
        # If authentication fails, fail immediately
        if cls.third_access_data is None:
            cls.assertClassSetupFailure('Authentication failed')

        images_service = cls.access_data.get_service(
            cls.images_config.endpoint_name)

        images_url_check = images_service.get_endpoint(
            cls.images_config.region)
        # If endpoint validation fails, fail immediately
        if images_url_check is None:
            cls.assertClassSetupFailure('Endpoint validation failed')

        cls.url = (images_service.get_endpoint(
            cls.images_config.region).public_url)
        # If a url override was provided, use it instead
        if cls.images_config.override_url:
            cls.url = cls.images_config.override_url

        cls.images_client = cls.generate_images_client(cls.access_data)
        cls.alt_images_client = cls.generate_images_client(cls.alt_access_data)
        cls.third_images_client = cls.generate_images_client(
            cls.third_access_data)

        cls.images_behavior = ImagesBehaviors(images_client=cls.images_client,
                                              images_config=cls.images_config)
        cls.alt_images_behavior = ImagesBehaviors(
            images_client=cls.alt_images_client,
            images_config=cls.images_config)
        cls.third_images_behavior = ImagesBehaviors(
            images_client=cls.third_images_client,
            images_config=cls.images_config)

        cls.alt_tenant_id = cls.alt_access_data.token.tenant.id_
        cls.error_msg = Messages.ERROR_MSG
        cls.export_to = cls.images_config.export_to
        cls.id_regex = re.compile(ImageProperties.ID_REGEX)
        cls.import_from = cls.images_config.import_from
        cls.import_from_bootable = cls.images_config.import_from_bootable
        cls.import_from_format = cls.images_config.import_from_format
        cls.max_created_at_delta = cls.images_config.max_created_at_delta
        cls.max_expires_at_delta = cls.images_config.max_expires_at_delta
        cls.max_updated_at_delta = cls.images_config.max_updated_at_delta
        cls.tenant_id = cls.access_data.token.tenant.id_
        cls.third_tenant_id = cls.third_access_data.token.tenant.id_

        cls.test_file = cls.read_data_file(cls.images_config.test_file)
        cls.image_schema_json = cls.read_data_file(
            cls.images_config.image_schema_json)
        cls.images_schema_json = cls.read_data_file(
            cls.images_config.images_schema_json)
        cls.image_member_schema_json = cls.read_data_file(
            cls.images_config.image_member_schema_json)
        cls.image_members_schema_json = cls.read_data_file(
            cls.images_config.image_members_schema_json)
        cls.task_schema_json = cls.read_data_file(
            cls.images_config.task_schema_json)
        cls.tasks_schema_json = cls.read_data_file(
            cls.images_config.tasks_schema_json)

        cls.addClassCleanup(cls.resources.release)
        cls.addClassCleanup(cls.images_behavior.resources.release)
        cls.addClassCleanup(cls.alt_images_behavior.resources.release)
        cls.addClassCleanup(cls.third_images_behavior.resources.release)
Esempio n. 37
0
    def setUpClass(cls):
        super(ComputeFixture, cls).setUpClass()
        cls.flavors_config = FlavorsConfig()
        cls.images_config = ImagesConfig()
        cls.servers_config = ServersConfig()
        cls.compute_endpoint = ComputeEndpointConfig()
        cls.marshalling = MarshallingConfig()
        cls.config_drive_config = ConfigDriveConfig()
        cls.cloud_init_config = CloudInitConfig()

        cls.flavor_ref = cls.flavors_config.primary_flavor
        cls.flavor_ref_alt = cls.flavors_config.secondary_flavor
        cls.image_ref = cls.images_config.primary_image
        cls.image_ref_alt = cls.images_config.secondary_image
        cls.disk_path = cls.servers_config.instance_disk_path
        cls.split_ephemeral_disk_enabled = \
            cls.servers_config.split_ephemeral_disk_enabled
        cls.ephemeral_disk_max_size = \
            cls.servers_config.ephemeral_disk_max_size
        cls.disk_format_type = cls.servers_config.disk_format_type
        cls.expected_networks = cls.servers_config.expected_networks
        cls.file_injection_enabled = \
            cls.servers_config.personality_file_injection_enabled

        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        cls.access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                       cls.user_config)
        # If authentication fails, halt
        if cls.access_data is None:
            cls.assertClassSetupFailure('Authentication failed.')

        compute_service = cls.access_data.get_service(
            cls.compute_endpoint.compute_endpoint_name)
        url = compute_service.get_endpoint(
            cls.compute_endpoint.region).public_url
        # If a url override was provided, use that value instead
        if cls.compute_endpoint.compute_endpoint_url:
            url = '{0}/{1}'.format(cls.compute_endpoint.compute_endpoint_url,
                                   cls.user_config.tenant_id)

        client_args = {'url': url, 'auth_token': cls.access_data.token.id_,
                       'serialize_format': cls.marshalling.serializer,
                       'deserialize_format': cls.marshalling.deserializer}

        cls.flavors_client = FlavorsClient(**client_args)
        cls.servers_client = ServersClient(**client_args)
        cls.boot_from_volume_client = VolumesBootClient(**client_args)
        cls.images_client = ImagesClient(**client_args)
        cls.keypairs_client = KeypairsClient(**client_args)
        cls.security_groups_client = SecurityGroupsClient(**client_args)
        cls.security_group_rule_client = SecurityGroupRulesClient(
            **client_args)
        cls.volume_attachments_client = VolumeAttachmentsAPIClient(
            url=url, auth_token=cls.access_data.token.id_,
            serialize_format=cls.marshalling.serializer,
            deserialize_format=cls.marshalling.deserializer)
        cls.rescue_client = RescueClient(**client_args)
        cls.vnc_client = VncConsoleClient(**client_args)
        cls.console_output_client = ConsoleOutputClient(**client_args)
        cls.limits_client = LimitsClient(**client_args)
        cls.server_behaviors = ServerBehaviors(
            servers_client=cls.servers_client,
            images_client=cls.images_client,
            servers_config=cls.servers_config,
            images_config=cls.images_config,
            flavors_config=cls.flavors_config)
        cls.volume_server_behaviors = VolumeServerBehaviors(
            servers_client=cls.servers_client,
            images_client=cls.images_client,
            servers_config=cls.servers_config,
            images_config=cls.images_config,
            flavors_config=cls.flavors_config,
            server_behaviors=cls.server_behaviors,
            boot_from_volume_client=cls.boot_from_volume_client)
        cls.image_behaviors = ImageBehaviors(cls.images_client,
                                             cls.servers_client,
                                             cls.images_config)
        cls.config_drive_behaviors = ConfigDriveBehaviors(cls.servers_client,
                                                          cls.servers_config,
                                                          cls.server_behaviors)
        cls.flavors_client.add_exception_handler(ExceptionHandler())
        cls.resources = ResourcePool()
        cls.addClassCleanup(cls.resources.release)
Esempio n. 38
0
def compute_cleanup():
    # Load necessary configurations
    compute_endpoint = ComputeEndpointConfig()
    marshalling = MarshallingConfig()

    endpoint_config = UserAuthConfig()
    user_config = UserConfig()
    access_data = AuthProvider.get_access_data(
        endpoint_config, user_config)

    # If authentication fails, halt
    if access_data is None:
        raise Exception('Authentication failed.')

    compute_service = access_data.get_service(
        compute_endpoint.compute_endpoint_name)
    url = compute_service.get_endpoint(
        compute_endpoint.region).public_url
    # If a url override was provided, use that value instead
    if compute_endpoint.compute_endpoint_url:
        url = '{0}/{1}'.format(compute_endpoint.compute_endpoint_url,
                               user_config.tenant_id)

    client_args = {'url': url, 'auth_token': access_data.token.id_,
                   'serialize_format': marshalling.serializer,
                   'deserialize_format': marshalling.deserializer}

    flavors_client = FlavorsClient(**client_args)
    servers_client = ServersClient(**client_args)
    images_client = ImagesClient(**client_args)

    keypairs_client = KeypairsClient(**client_args)
    flavors_client.add_exception_handler(ExceptionHandler())

    keys = keypairs_client.list_keypairs().entity
    print 'Preparing to delete {count} keys...'.format(count=len(keys))
    for key in keys:
        try:
            keypairs_client.delete_keypair(key.name)
        except Exception:
            print 'Failed to delete key {id}: {exception}'.format(
                id=key.id, exception=traceback.format_exc())

    servers = servers_client.list_servers_with_detail().entity
    print 'Preparing to delete {count} servers...'.format(count=len(servers))
    for server in servers:
        try:
            servers_client.delete_server(server.id)
        except Exception:
            print 'Failed to delete server {id}: {exception}'.format(
                id=server.id, exception=traceback.format_exc())

    images = images_client.list_images(image_type='snapshot').entity
    print 'Preparing to delete {count} image snapshots...'.format(count=len(images))
    for image in images:
        try:
            images_client.delete_image(image.id)
        except Exception:
            print 'Failed to delete image {id}: {exception}'.format(
                id=image.id, exception=traceback.format_exc())

    if raxcafe_installed:
        nova_networks_client = NovaNetworksClient(**client_args)
        raw_networks = nova_networks_client.list_networks().entity

        # remove the public and snet networks as well as any additional
        # networks to be preserved
        networks = [nw for nw in raw_networks if nw.id_ not in preserved_networks]

        print 'Preparing to delete {count} networks...'.format(count=len(networks))
        for network in networks:
            try:
                nova_networks_client.delete_network(network.id_)
            except Exception:
                print 'Failed to delete network {id}: {exception}'.format(
                    id=network.id_, exception=traceback.format_exc())
Esempio n. 39
0
def _set_up_clients():
    """
    Read the user creds from the configuration file in and constructs all the
    service clients.  If it can't authenticate, or it cannot construct the
    autoscale/server/lbaas clients, then it fails.

    The RCv3 client is not created if the account does not have access to RCv3
    or if RCv3 configuration parameters are not present or invalid.
    """
    user_config = UserConfig()
    access_data = AuthProvider.get_access_data(endpoint_config, user_config)

    if access_data is None:
        raise Exception(
            "Unable to authenticate against identity to get auth token and "
            "service catalog.")

    _autoscale_client = _make_client(
        access_data,
        autoscale_config.autoscale_endpoint_name,
        autoscale_config.region,
        AutoscalingAPIClient,
        "Autoscale")

    _server_client = _make_client(
        access_data,
        autoscale_config.server_endpoint_name,
        autoscale_config.server_region_override or autoscale_config.region,
        ServersClient,
        "Nova Compute")

    _images_client = _make_client(
        access_data,
        autoscale_config.server_endpoint_name,
        autoscale_config.region,
        ImagesClient,
        "Nova images")

    _lbaas_client = _make_client(
        access_data,
        autoscale_config.load_balancer_endpoint_name,
        autoscale_config.lbaas_region_override or autoscale_config.region,
        LbaasAPIClient,
        "Cloud Load Balancers")

    _rcv3_client = None
    if _rcv3_cloud_network and _rcv3_load_balancer_pool:
        _rcv3_client = _make_client(
            access_data,
            autoscale_config.rcv3_endpoint_name,
            autoscale_config.rcv3_region_override or autoscale_config.region,
            RackConnectV3APIClient,
            "RackConnect v3")
    else:
        print("Not enough test configuration for RCv3 provided. "
              "Will not run RCv3 tests.")

    if not all([x is not None for x in (_autoscale_client, _server_client,
                                        _lbaas_client)]):
        raise Exception(
            "Unable to instantiate all necessary clients.")

    return (_autoscale_client, _server_client, _images_client, _lbaas_client,
            _rcv3_client)
Esempio n. 40
0
    def setUpClass(cls):
        """
        Initialize autoscale configs, behaviors and client
        """
        super(AutoscaleFixture, cls).setUpClass()
        cls.resources = ResourcePool()
        cls.autoscale_config = AutoscaleConfig()
        cls.endpoint_config = UserAuthConfig()
        user_config = UserConfig()
        access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                   user_config)
        server_service = access_data.get_service(
            cls.autoscale_config.server_endpoint_name)
        load_balancer_service = access_data.get_service(
            cls.autoscale_config.load_balancer_endpoint_name)
        server_url = server_service.get_endpoint(
            cls.autoscale_config.region).public_url
        lbaas_url = load_balancer_service.get_endpoint(
            cls.autoscale_config.region).public_url

        cls.tenant_id = cls.autoscale_config.tenant_id

        env = os.environ['OSTNG_CONFIG_FILE']
        if ('preprod' in env.lower()) or ('dev' in env.lower()):
            cls.url = str(cls.autoscale_config.server_endpoint) + \
                '/' + str(cls.tenant_id)
        else:
            autoscale_service = access_data.get_service(
                cls.autoscale_config.autoscale_endpoint_name)
            cls.url = autoscale_service.get_endpoint(
                cls.autoscale_config.region).public_url

        cls.autoscale_client = AutoscalingAPIClient(
            cls.url, access_data.token.id_,
            'json', 'json')
        cls.server_client = ServersClient(
            server_url, access_data.token.id_,
            'json', 'json')
        cls.lbaas_client = LbaasAPIClient(
            lbaas_url, access_data.token.id_,
            'json', 'json')
        cls.autoscale_behaviors = AutoscaleBehaviors(cls.autoscale_config,
                                                     cls.autoscale_client)
        cls.gc_name = cls.autoscale_config.gc_name
        cls.gc_cooldown = int(cls.autoscale_config.gc_cooldown)
        cls.gc_min_entities = int(cls.autoscale_config.gc_min_entities)
        cls.gc_min_entities_alt = int(cls.autoscale_config.gc_min_entities_alt)
        cls.gc_max_entities = int(cls.autoscale_config.gc_max_entities)
        cls.lc_name = cls.autoscale_config.lc_name
        cls.lc_flavor_ref = cls.autoscale_config.lc_flavor_ref
        cls.lc_image_ref = cls.autoscale_config.lc_image_ref
        cls.lc_image_ref_alt = cls.autoscale_config.lc_image_ref_alt
        cls.sp_name = rand_name(cls.autoscale_config.sp_name)
        cls.sp_cooldown = int(cls.autoscale_config.sp_cooldown)
        cls.sp_change = int(cls.autoscale_config.sp_change)
        cls.sp_change_percent = int(cls.autoscale_config.sp_change_percent)
        cls.sp_desired_capacity = int(cls.autoscale_config.sp_desired_capacity)
        cls.sp_policy_type = cls.autoscale_config.sp_policy_type
        cls.check_type = cls.autoscale_config.check_type
        cls.check_url = cls.autoscale_config.check_url
        cls.check_method = cls.autoscale_config.check_method
        cls.check_timeout = cls.autoscale_config.check_timeout
        cls.check_period = cls.autoscale_config.check_period
        cls.monitoring_zones = ['mzord', 'mzdfw', 'mziad']
        cls.target_alias = cls.autoscale_config.target_alias
        cls.alarm_criteria = cls.autoscale_config.alarm_criteria
        cls.upd_sp_change = int(cls.autoscale_config.upd_sp_change)
        cls.lc_load_balancers = cls.autoscale_config.lc_load_balancers
        cls.sp_list = cls.autoscale_config.sp_list
        cls.wb_name = rand_name(cls.autoscale_config.wb_name)
        cls.load_balancer_1 = int(cls.autoscale_config.load_balancer_1)
        cls.load_balancer_2 = int(cls.autoscale_config.load_balancer_2)
        cls.load_balancer_3 = int(cls.autoscale_config.load_balancer_3)
        cls.lb_other_region = int(cls.autoscale_config.lb_other_region)
        cls.interval_time = int(cls.autoscale_config.interval_time)
        cls.timeout = int(cls.autoscale_config.timeout)
        cls.scheduler_interval = OtterConstants.SCHEDULER_INTERVAL
        cls.scheduler_batch = OtterConstants.SCHEDULER_BATCH
        cls.max_maxentities = OtterConstants.MAX_MAXENTITIES
        cls.max_cooldown = OtterConstants.MAX_COOLDOWN
        cls.max_groups = OtterConstants.MAX_GROUPS
        cls.max_policies = OtterConstants.MAX_POLICIES
        cls.max_webhooks = OtterConstants.MAX_WEBHOOKS
        cls.limit_value_all = OtterConstants.LIMIT_VALUE_ALL
        cls.limit_unit_all = OtterConstants.LIMIT_UNIT_ALL
        cls.limit_value_webhook = OtterConstants.LIMIT_VALUE_WEBHOOK
        cls.limit_unit_webhook = OtterConstants.LIMIT_UNIT_WEBHOOK
        cls.pagination_limit = OtterConstants.PAGINATION_LIMIT
        cls.personality_maxlength = OtterConstants.PERSONALITY_MAXLENGTH
        cls.max_personalities = OtterConstants.PERSONALITIES_PER_SERVER
        cls.personality_max_file_size = OtterConstants.PERSONAITY_FILE_SIZE
        cls.non_autoscale_username = cls.autoscale_config.non_autoscale_username
        cls.non_autoscale_password = cls.autoscale_config.non_autoscale_password
        cls.non_autoscale_tenant = cls.autoscale_config.non_autoscale_tenant
Esempio n. 41
0
    def setUpClass(cls):
        super(ImagesFixture, cls).setUpClass()
        cls.images_config = ImagesConfig()
        cls.marshalling = MarshallingConfig()
        cls.endpoint_config = UserAuthConfig()
        cls.user_config = UserConfig()
        cls.alt_user_config = AltUserConfig()
        cls.third_user_config = ThirdUserConfig()
        cls.resources = ResourcePool()
        cls.serialize_format = cls.marshalling.serializer
        cls.deserialize_format = cls.marshalling.deserializer
        cls.image_data = '*' * 1024
        cls.file_data = StringIO.StringIO(cls.image_data)

        cls.access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                       cls.user_config)
        # If authentication fails, fail immediately
        if cls.access_data is None:
            cls.assertClassSetupFailure('Authentication failed')

        cls.alt_access_data = AuthProvider.get_access_data(cls.endpoint_config,
                                                           cls.alt_user_config)
        # If authentication fails, fail immediately
        if cls.alt_access_data is None:
            cls.assertClassSetupFailure('Authentication failed')
        cls.third_access_data = AuthProvider.get_access_data(
            cls.endpoint_config, cls.third_user_config)
        # If authentication fails, fail immediately
        if cls.third_access_data is None:
            cls.assertClassSetupFailure('Authentication failed')

        images_service = cls.access_data.get_service(
            cls.images_config.endpoint_name)

        images_url_check = images_service.get_endpoint(
            cls.images_config.region)
        # If endpoint validation fails, fail immediately
        if images_url_check is None:
            cls.assertClassSetupFailure('Endpoint validation failed')

        cls.url = (images_service.get_endpoint(
            cls.images_config.region).public_url)
        # If a url override was provided, use it instead
        if cls.images_config.override_url:
            cls.url = cls.images_config.override_url

        cls.images_client = cls.generate_images_client(cls.access_data)
        cls.alt_images_client = cls.generate_images_client(cls.alt_access_data)
        cls.third_images_client = cls.generate_images_client(
            cls.third_access_data)

        cls.images_behavior = ImagesBehaviors(
            images_client=cls.images_client, images_config=cls.images_config)
        cls.alt_images_behavior = ImagesBehaviors(
            images_client=cls.alt_images_client,
            images_config=cls.images_config)
        cls.third_images_behavior = ImagesBehaviors(
            images_client=cls.third_images_client,
            images_config=cls.images_config)

        cls.alt_tenant_id = cls.alt_access_data.token.tenant.id_
        cls.error_msg = Messages.ERROR_MSG
        cls.export_to = cls.images_config.export_to
        cls.id_regex = re.compile(ImageProperties.ID_REGEX)
        cls.import_from = cls.images_config.import_from
        cls.import_from_bootable = cls.images_config.import_from_bootable
        cls.import_from_format = cls.images_config.import_from_format
        cls.max_created_at_delta = cls.images_config.max_created_at_delta
        cls.max_expires_at_delta = cls.images_config.max_expires_at_delta
        cls.max_updated_at_delta = cls.images_config.max_updated_at_delta
        cls.tenant_id = cls.access_data.token.tenant.id_
        cls.test_file = open(cls.images_config.test_file).read().rstrip()
        cls.third_tenant_id = cls.third_access_data.token.tenant.id_

        cls.image_schema_json = (
            open(cls.images_config.image_schema_json).read().rstrip())
        cls.images_schema_json = (
            open(cls.images_config.images_schema_json).read().rstrip())
        cls.image_member_schema_json = (
            open(cls.images_config.image_member_schema_json).read().rstrip())
        cls.image_members_schema_json = (
            open(cls.images_config.image_members_schema_json).read().rstrip())
        cls.task_schema_json = (
            open(cls.images_config.task_schema_json).read().rstrip())
        cls.tasks_schema_json = (
            open(cls.images_config.tasks_schema_json).read().rstrip())

        cls.addClassCleanup(cls.resources.release)
        cls.addClassCleanup(cls.images_behavior.resources.release)
        cls.addClassCleanup(cls.alt_images_behavior.resources.release)
        cls.addClassCleanup(cls.third_images_behavior.resources.release)