Пример #1
0
def text_get_all_complexes(mock_send):
    """Test get_all Complex class method."""
    mock_send.return_value = {}
    assert len(list(Complex.get_all())) == 0

    mock_send.return_value = COMPLEXES
    assert len(list(Complex.get_all())) == 2
Пример #2
0
def test_complex_get_by_physical_location_id(mock_send_message_json):
    """Test complex get_by_physical_location_id url creation."""
    Complex.get_by_physical_location_id("test")
    assert mock_send_message_json.called_once_with(
        "GET", "Get complex with physical location id: test",
        f"{Complex.base_url}{Complex.api_version}/cloud-infrastructure/"
        f"complexes/complex/test")
Пример #3
0
def test_complex_delete(mock_send_message):
    cmplx = Complex(physical_location_id="test_location_id",
                    resource_version="1234")
    cmplx.delete()
    mock_send_message.assert_called_once_with(
        "DELETE", "Delete test_location_id complex",
        f"{cmplx.url}?resource-version={cmplx.resource_version}")
Пример #4
0
def test_create_complex(mock_send):
    """Test complex creation"""
    cmplx = Complex.create(
        name="test complex",
        physical_location_id="somewhere",
        data_center_code="5555",
        physical_location_type="test",
        city="Test City",
        postal_code="55555",
        region="Test region",
        elevation="TestElevation",
    )

    assert cmplx.name == "test complex"
    assert cmplx.physical_location_id == "somewhere"
    assert cmplx.identity_url == ""
    assert cmplx.physical_location_type == "test"
    assert cmplx.street1 == ""
    assert cmplx.street2 == ""
    assert cmplx.city == "Test City"
    assert cmplx.state == ""
    assert cmplx.postal_code == "55555"
    assert cmplx.country == ""
    assert cmplx.region == "Test region"
    assert cmplx.latitude == ""
    assert cmplx.longitude == ""
    assert cmplx.elevation == "TestElevation"
    assert cmplx.lata == ""
Пример #5
0
def test_complex_get_all(mock_send_message_json):
    mock_send_message_json.return_value = COMPLEXES
    complexes = list(Complex.get_all())
    assert len(complexes) == 1
    cmplx = complexes[0]
    assert cmplx.name == "integration_test_complex"
    assert cmplx.physical_location_id == "integration_test_complex"
def test_complex_get_all():
    requests.get(f"{Complex.base_url}/reset")
    complexes = list(Complex.get_all())
    assert len(complexes) == 0

    cmplx: Complex = Complex.create(
        name="test_complex", physical_location_id="test_physical_location_id")
    assert cmplx.name == "test_complex"
    assert cmplx.physical_location_id == "test_physical_location_id"

    complexes = list(Complex.get_all())
    assert len(complexes) == 1

    cmplx = complexes[0]
    assert cmplx.name == "test_complex"
    assert cmplx.physical_location_id == "test_physical_location_id"
Пример #7
0
def test_complex(mock_send_message):
    cmplx = Complex(name="test_complex_name",
                    physical_location_id="test_location_id",
                    resource_version="1234")
    assert cmplx.name == "test_complex_name"
    assert cmplx.physical_location_id == "test_location_id"
    assert cmplx.url == (f"{Complex.base_url}{Complex.api_version}/cloud-infrastructure/"
                         "complexes/complex/test_location_id?resource-version=1234")

    cmplx2 = Complex.create(name="test_complex_name",
                            physical_location_id="test_location_id")
    mock_send_message.assert_called_once()    
    assert cmplx2.name == "test_complex_name"
    assert cmplx2.physical_location_id == "test_location_id"
    assert cmplx2.url == (f"{Complex.base_url}{Complex.api_version}/cloud-infrastructure/"
                         "complexes/complex/test_location_id?resource-version=")
    method, _, url = mock_send_message.call_args[0]
    assert method == "PUT"
    assert url == (f"{Complex.base_url}{Complex.api_version}/cloud-infrastructure/"
                   "complexes/complex/test_location_id")
def test_link_cloud_region_to_complex():

    requests.get(f"{Complex.base_url}/reset")

    cmplx: Complex = Complex.create(
        name="test_complex", physical_location_id="test_physical_location_id")
    cloud_region: CloudRegion = CloudRegion.create("test_owner",
                                                   "test_cloud_region",
                                                   orchestration_disabled=True,
                                                   in_maint=False)

    assert len(list(cloud_region.relationships)) == 0
    cloud_region.link_to_complex(cmplx)
    assert len(list(cloud_region.relationships)) == 1
    def execute(self):
        """Link cloud region to complex.

        Use settings values:
         - COMPLEX_PHYSICAL_LOCATION_ID,
         - CLOUD_REGION_CLOUD_OWNER,
         - CLOUD_REGION_ID.
        """
        super().execute()
        cmplx = Complex(
            physical_location_id=settings.COMPLEX_PHYSICAL_LOCATION_ID,
            name=settings.COMPLEX_PHYSICAL_LOCATION_ID
        )
        cloud_region = CloudRegion.get_by_id(
            cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
            cloud_region_id=settings.CLOUD_REGION_ID,
        )
        cloud_region.link_to_complex(cmplx)
Пример #10
0
def test_cloud_region_link_to_complex(mock_add_rel):
    """Test Cloud Region linking with Complex.

    Test Relationship object creation
    """
    cloud_region = CloudRegion(cloud_owner="test_cloud_owner",
                               cloud_region_id="test_cloud_region",
                               orchestration_disabled=True,
                               in_maint=False)
    cmplx = Complex(name="test_complex_name",
                    physical_location_id="test_location_id",
                    resource_version="1234")
    cloud_region.link_to_complex(cmplx)
    mock_add_rel.assert_called_once()
    relationship = mock_add_rel.call_args[0][0]
    assert relationship.related_to == "complex"
    assert relationship.related_link == (f"aai/v13/cloud-infrastructure/complexes/"
                                         f"complex/test_location_id")
    assert len(relationship.relationship_data) == 2
Пример #11
0
def test_complex_count(mock_send_message_json):
    mock_send_message_json.return_value = COMPLEXES_COUNT
    assert Complex.count() == 12
Пример #12
0
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)

MYPATH = os.path.dirname(os.path.realpath(__file__))

#### Create complex if not exists ####
logger.info("******** Complex *******")
try:
    complex = list(Complex.get_all(physical_location_id=Config.COMPLEX_ID))[0]
    logger.info("Complex exists")
except IndexError:
    logger.info("Complex does not exists")
    complex = Complex.create(physical_location_id=Config.COMPLEX_ID,
                             name=Config.COMPLEX_ID,
                             physical_location_type="office",
                             street1="DummyStreet 1",
                             city="DummyCity",
                             postal_code="00-000",
                             country="DummyCountry",
                             region="DummyRegion")
    logger.info("Complex created")

#### Create cloud region if not exists ####
logger.info("******** Cloud Region *******")