def test_customers_get_all(mock_send): """Test get_all Customer class method.""" mock_send.return_value = {} customers = list(Customer.get_all()) assert len(customers) == 0 mock_send.return_value = CUSTOMERS customers = list(Customer.get_all()) assert len(customers) == 1
def test_customers(mock_send): """Test get_customer function of A&AI.""" mock_send.return_value = SIMPLE_CUSTOMER assert len(list(Customer.get_all())) == 1 aai_customer_1 = next(Customer.get_all()) assert aai_customer_1.global_customer_id == "generic" assert aai_customer_1.subscriber_name == "generic" assert aai_customer_1.subscriber_type == "INFRA" assert aai_customer_1.resource_version == "1561218640404" mock_send.assert_called_with("GET", 'get customers', mock.ANY)
def test_customer_service_subscription_cloud_region(mock_cloud_region, mock_send_serv_sub, mock_send): """Test Customer's service subscription cloud region object.""" mock_send.return_value = CUSTOMERS customer = next(Customer.get_all()) mock_send.return_value = SERVICE_SUBSCRIPTION service_subscription = customer.get_service_subscription_by_service_type( "freeradius") mock_send_serv_sub.return_value = {} relationships = list(service_subscription.relationships) assert len(relationships) == 0 with pytest.raises(AttributeError): service_subscription.cloud_region with pytest.raises(AttributeError): service_subscription.tenant mock_cloud_region.return_value = CLOUD_REGION mock_send_serv_sub.return_value = SERVICE_SUBSCRIPTION_RELATIONSHIPS relationships = list(service_subscription.relationships) assert len(relationships) == 1 cloud_region = service_subscription.cloud_region assert cloud_region.cloud_owner == "OPNFV" assert cloud_region.cloud_region_id == "RegionOne" assert cloud_region.cloud_type == "openstack" mock_cloud_region.side_effect = ValueError with pytest.raises(AttributeError): service_subscription.tenant mock_cloud_region.side_effect = [CLOUD_REGION, TENANT] tenant = service_subscription.tenant assert tenant.tenant_id == "4bdc6f0f2539430f9428c852ba606808" assert tenant.name == "onap-dublin-daily-vnfs"
def test_create_customer(): requests.get(f"{Customer.base_url}/reset") customers = list(Customer.get_all()) assert len(customers) == 0 customer = Customer.create(global_customer_id="test_global_customer_id", subscriber_name="test_subscriber_name", subscriber_type="test_subscriber_type") assert customer.global_customer_id == "test_global_customer_id" assert customer.subscriber_name == "test_subscriber_name" assert customer.subscriber_type == "test_subscriber_type" customers = list(Customer.get_all()) assert len(customers) == 1
def test_customer_service_tenant_relations(mock_send): """Test the retrieval of service/tenant relations in A&AI.""" mock_send.return_value = SIMPLE_CUSTOMER customer = next(Customer.get_all()) mock_send.return_value = SERVICE_SUBSCRIPTION res = list(customer.service_subscriptions) assert len(res) == 2 assert res[0].service_type == "freeradius"
def test_customer_get_service_subscription_by_service_type(mock_send): """Test Customer's get_service_subscription_by_service_type method.""" mock_send.return_value = CUSTOMERS customer = next(Customer.get_all()) mock_send.return_value = SERVICE_SUBSCRIPTION service_subscription = customer.get_service_subscription_by_service_type("freeradius") assert service_subscription.service_type == "freeradius"
def test_customer_service_subscription_service_instance(mock_send_serv_sub, mock_send): """Test Customer's service subscription service instances.""" mock_send.return_value = CUSTOMERS customer = next(Customer.get_all()) mock_send.return_value = SERVICE_SUBSCRIPTION service_subscription = customer.get_service_subscription_by_service_type("freeradius") mock_send_serv_sub.return_value = SERVICE_INSTANCES service_instances = list(service_subscription.service_instances) assert len(service_instances) == 1 service_instance = service_instances[0] assert service_instance.instance_name == "test" assert service_instance.instance_id == "5410bf79-2aa3-450e-a324-ec5630dc18cf" assert service_instance.service_subscription == service_subscription assert service_instance.url == (f"{service_subscription.url}/service-instances/" f"service-instance/{service_instance.instance_id}")
def resolve_hc_inputs(): logger.info("******** Check Customer *******") customer = None for found_customer in list(Customer.get_all()): logger.debug("Customer %s found", found_customer.subscriber_name) if found_customer.subscriber_name == Config.GLOBAL_CUSTOMER_ID: logger.info("Customer %s found", found_customer.subscriber_name) customer = found_customer break if customer is None: raise Exception("Customer %s wasn't found in ONAP" % Config.GLOBAL_CUSTOMER_ID) logger.info("******** Check Service Subscription *******") service_subscription = None for service_sub in customer.service_subscriptions: logger.debug("Service subscription %s is found", service_sub.service_type) if service_sub.service_type == Config.SERVICENAME: logger.info("Service %s subscribed", Config.SERVICENAME) service_subscription = service_sub break logger.info("******** Retrieve Service Metadata *******") service_instance = None for single_service in service_subscription.service_instances: if single_service.instance_name == Config.SERVICE_INSTANCE_NAME: service_instance = single_service break service_id = service_instance.instance_id vnfs = list(service_instance.vnf_instances) if len(vnfs) > 1: raise NotImplementedError( "Service %s is composed of more than one vnf!" % service_id) if not vnfs: raise Exception("Service %s doesn't contain any vnfs" % service_id) vnf_id = vnfs[0].vnf_id return service_id, vnf_id
def test_customers_no_resources(mock_send): """Test get_customer function with no customer declared in A&AI.""" mock_send.return_value = CUSTOMERS_NO_RESOURCES assert len(list(Customer.get_all())) == 0 mock_send.assert_called_with("GET", 'get customers', mock.ANY)
logger = logging.getLogger("") logger.setLevel(logging.DEBUG) fh = logging.StreamHandler() fh_formatter = logging.Formatter( '%(asctime)s %(levelname)s %(lineno)d:%(filename)s(%(process)d) - %(message)s' ) fh.setFormatter(fh_formatter) logger.addHandler(fh) logger.info("*******************************") logger.info("**** SERVICE INSTANTIATION ****") logger.info("*******************************") logger.info("******** Create Customer *******") customer = None for found_customer in list(Customer.get_all()): logger.debug("Customer %s found", found_customer.subscriber_name) if found_customer.subscriber_name == Config.GLOBAL_CUSTOMER_ID: logger.info("Customer %s found", found_customer.subscriber_name) customer = found_customer break if not customer: customer = Customer.create(Config.GLOBAL_CUSTOMER_ID, Config.GLOBAL_CUSTOMER_ID, "INFRA") logger.info("******** Find Service in SDC *******") service = None services = Service.get_all() for found_service in services: logger.debug("Service %s is found, distribution %s", found_service.name, found_service.distribution_status)