Search in sources :

Example 1 with Resource

use of org.openstack4j.model.heat.Resource in project so by onap.

the class CreateAAIInventory method heatbridge.

public void heatbridge(CloudInformation cloudInformation) throws HeatBridgeException, MsoCloudSiteNotFound {
    CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId()).orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
    if (cloudSite.getOrchestrator() != null && MULTICLOUD_MODE.equalsIgnoreCase(cloudSite.getOrchestrator())) {
        logger.debug("Skipping Heatbridge as CloudSite orchestrator is: " + MULTICLOUD_MODE);
        return;
    }
    CloudIdentity cloudIdentity = cloudSite.getIdentityService();
    String heatStackId = cloudInformation.getTemplateInstanceId().split("/")[1];
    List<String> oobMgtNetNames = new ArrayList<>();
    HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation);
    heatBridgeClient.authenticate();
    List<Resource> stackResources = heatBridgeClient.queryNestedHeatStackResources(cloudInformation.getTemplateInstanceId());
    List<Network> osNetworks = heatBridgeClient.getAllOpenstackProviderNetworks(stackResources);
    heatBridgeClient.buildAddNetworksToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), osNetworks);
    List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources);
    heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources);
    List<Image> osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers);
    List<Flavor> osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers);
    logger.debug("Successfully queried heat stack{} for resources.", heatStackId);
    // os images
    if (osImages != null && !osImages.isEmpty()) {
        heatBridgeClient.buildAddImagesToAaiAction(osImages);
        logger.debug("Successfully built AAI actions to add images.");
    } else {
        logger.debug("No images to update to AAI.");
    }
    // flavors
    if (osFlavors != null && !osFlavors.isEmpty()) {
        heatBridgeClient.buildAddFlavorsToAaiAction(osFlavors);
        logger.debug("Successfully built AAI actions to add flavors.");
    } else {
        logger.debug("No flavors to update to AAI.");
    }
    // compute resources
    heatBridgeClient.buildAddVserversToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), osServers);
    logger.debug("Successfully queried compute resources and built AAI vserver actions.");
    // neutron resources
    List<String> oobMgtNetIds = new ArrayList<>();
    // if no network-id list is provided, however network-name list is
    if (!CollectionUtils.isEmpty(oobMgtNetNames)) {
        oobMgtNetIds = heatBridgeClient.extractNetworkIds(oobMgtNetNames);
    }
    heatBridgeClient.buildAddVserverLInterfacesToAaiAction(stackResources, oobMgtNetIds, cloudInformation.getOwner());
    logger.debug("Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
    heatBridgeClient.buildAddVolumes(stackResources);
    // Update AAI
    logger.debug("Current Dry Run Value: {}", env.getProperty("heatBridgeDryrun", Boolean.class, false));
    heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false));
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) Server(org.openstack4j.model.compute.Server) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) ArrayList(java.util.ArrayList) Resource(org.openstack4j.model.heat.Resource) Image(org.openstack4j.model.compute.Image) Flavor(org.openstack4j.model.compute.Flavor) CloudSite(org.onap.so.db.catalog.beans.CloudSite) HeatBridgeApi(org.onap.so.heatbridge.HeatBridgeApi) Network(org.openstack4j.model.network.Network)

Example 2 with Resource

use of org.openstack4j.model.heat.Resource in project so by onap.

the class HeatBridgeImplTest method testUpdateLInterfaceVlan.

@Test
public void testUpdateLInterfaceVlan() throws HeatBridgeException {
    // Arrange
    List<Resource> stackResources = (List<Resource>) extractTestStackResources();
    Port port = mock(Port.class);
    when(port.getId()).thenReturn("test-port-id");
    when(port.getName()).thenReturn("test-port-name");
    when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
    when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
    when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
    when(port.getDeviceId()).thenReturn("test-device-id");
    LInterface lIf = new LInterface();
    lIf.setInterfaceId("test-port-id");
    lIf.setInterfaceType("SRIOV");
    lIf.setInterfaceName("name");
    String pfPciId = "0000:08:00.0";
    when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id"));
    IP ip = mock(IP.class);
    Set<IP> ipSet = new HashSet<>();
    ipSet.add(ip);
    when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226");
    when(ip.getSubnetId()).thenReturn("testSubnetId");
    when(port.getFixedIps()).thenAnswer(x -> ipSet);
    Subnet subnet = mock(Subnet.class);
    when(subnet.getCidr()).thenReturn("169.254.100.0/24");
    when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet);
    Network network = mock(Network.class);
    when(network.getId()).thenReturn("test-network-id");
    when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
    when(network.getProviderSegID()).thenReturn("2345");
    when(network.getProviderPhyNet()).thenReturn("ovsnet");
    doNothing().when(heatbridge).processOVS(any(), any(), any());
    when(osClient.getNetworkById(anyString())).thenReturn(network);
    SriovPf sriovPf = new SriovPf();
    sriovPf.setPfPciId(pfPciId);
    PInterface pIf = mock(PInterface.class);
    when(pIf.getInterfaceName()).thenReturn("test-port-id");
    when(resourcesClient.get(eq(PInterface.class), any(AAIResourceUri.class))).thenReturn(Optional.of(pIf));
    // Act
    heatbridge.createVlanAndSriovVF(port, lIf, "hostname");
    // Assert
    verify(transaction, times(2)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
    verify(osClient, times(1)).getNetworkById(anyString());
    verify(heatbridge, times(0)).processOVS(any(), any(), any());
}
Also used : Optional(java.util.Optional) Port(org.openstack4j.model.network.Port) IP(org.openstack4j.model.network.IP) Resource(org.openstack4j.model.heat.Resource) HeatResource(org.openstack4j.openstack.heat.domain.HeatResource) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SriovPf(org.onap.aai.domain.yang.SriovPf) PInterface(org.onap.aai.domain.yang.PInterface) Network(org.openstack4j.model.network.Network) LInterface(org.onap.aai.domain.yang.LInterface) List(java.util.List) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) Subnet(org.openstack4j.model.network.Subnet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Resource

use of org.openstack4j.model.heat.Resource in project so by onap.

the class HeatBridgeImplTest method testUpdateVserverLInterfacesToAai_skipVlans.

@Test
public void testUpdateVserverLInterfacesToAai_skipVlans() throws HeatBridgeException, JsonParseException, JsonMappingException, IOException {
    // Arrange
    List<Resource> stackResources = (List<Resource>) extractTestStackResources();
    Port port = mock(Port.class);
    when(port.getId()).thenReturn("test-port-id");
    when(port.getName()).thenReturn("test-port-name");
    when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
    when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
    when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
    when(port.getDeviceId()).thenReturn("test-device-id");
    String pfPciId = "0000:08:00.0";
    when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id"));
    Network network = mock(Network.class);
    when(network.getId()).thenReturn("test-network-id");
    when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
    when(network.getProviderSegID()).thenReturn("2345");
    when(osClient.getPortById("212a203a-9764-4f42-84ea-731536a8f13a")).thenReturn(port);
    when(osClient.getPortById("387e3904-8948-43d1-8635-b6c2042b54da")).thenReturn(port);
    when(osClient.getPortById("70a09dfd-f1c5-4bc8-bd8f-dc539b8d662a")).thenReturn(port);
    when(osClient.getPortById("12f88b4d-c8a4-4fbd-bcb4-7e36af02430b")).thenReturn(port);
    when(osClient.getPortById("c54b9f45-b413-4937-bbe4-3c8a5689cfc9")).thenReturn(port);
    when(osClient.getNetworkById(anyString())).thenReturn(network);
    PInterface pIf = mock(PInterface.class);
    when(pIf.getInterfaceName()).thenReturn("test-port-id");
    doNothing().when(heatbridge).updateSriovPfToSriovVF(any(), any());
    // Act
    heatbridge.buildAddVserverLInterfacesToAaiAction(stackResources, Arrays.asList("1", "2"), "CloudOwner");
    // Assert
    verify(transaction, times(5)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
    verify(osClient, times(5)).getPortById(anyString());
    verify(osClient, times(5)).getNetworkById(anyString());
}
Also used : PInterface(org.onap.aai.domain.yang.PInterface) Optional(java.util.Optional) Port(org.openstack4j.model.network.Port) Network(org.openstack4j.model.network.Network) Resource(org.openstack4j.model.heat.Resource) HeatResource(org.openstack4j.openstack.heat.domain.HeatResource) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) List(java.util.List) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 4 with Resource

use of org.openstack4j.model.heat.Resource in project so by onap.

the class HeatBridgeImplTest method testUpdateVserverLInterfacesToAai.

@Test
public void testUpdateVserverLInterfacesToAai() throws HeatBridgeException, JsonParseException, JsonMappingException, IOException {
    // Arrange
    List<Resource> stackResources = (List<Resource>) extractTestStackResources();
    Port port = mock(Port.class);
    when(port.getId()).thenReturn("test-port-id");
    when(port.getHostId()).thenReturn("pserverId");
    when(port.getName()).thenReturn("test-port-name");
    when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
    when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
    when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
    when(port.getDeviceId()).thenReturn("test-device-id");
    when(osClient.getServerById("test-device-id")).thenReturn(server);
    when(server.getHypervisorHostname()).thenReturn("test.server.name");
    String pfPciId = "0000:08:00.0";
    when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, HeatBridgeConstants.OS_PF_PCI_SLOT_KEY, "testPfPciId"));
    IP ip = mock(IP.class);
    Set<IP> ipSet = new HashSet<>();
    ipSet.add(ip);
    when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226");
    when(ip.getSubnetId()).thenReturn("testSubnetId");
    when(port.getFixedIps()).thenAnswer(x -> ipSet);
    Subnet subnet = mock(Subnet.class);
    when(subnet.getCidr()).thenReturn("169.254.100.0/24");
    when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet);
    Network network = mock(Network.class);
    when(network.getId()).thenReturn("test-network-id");
    when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
    when(network.getProviderSegID()).thenReturn("2345");
    when(network.getProviderPhyNet()).thenReturn("ovsnet");
    when(osClient.getPortById("212a203a-9764-4f42-84ea-731536a8f13a")).thenReturn(port);
    when(osClient.getPortById("387e3904-8948-43d1-8635-b6c2042b54da")).thenReturn(port);
    when(osClient.getPortById("70a09dfd-f1c5-4bc8-bd8f-dc539b8d662a")).thenReturn(port);
    when(osClient.getPortById("12f88b4d-c8a4-4fbd-bcb4-7e36af02430b")).thenReturn(port);
    when(osClient.getPortById("c54b9f45-b413-4937-bbe4-3c8a5689cfc9")).thenReturn(port);
    when(osClient.getNetworkById(anyString())).thenReturn(network);
    SriovPf sriovPf = new SriovPf();
    sriovPf.setPfPciId(pfPciId);
    when(resourcesClient.exists(any(AAIResourceUri.class))).thenReturn(true);
    when(env.getProperty("mso.cloudOwner.included", "")).thenReturn("CloudOwner");
    doReturn(dSLQueryClient).when(heatbridge).getAAIDSLClient();
    List<Pathed> pathed = ((Results<Pathed>) MAPPER.readValue(getJson("pathed-sriov-pf.json"), new TypeReference<Results<Pathed>>() {
    })).getResult();
    when(dSLQueryClient.queryPathed(any(DSLQuery.class))).thenReturn(pathed);
    doReturn(false).when(heatbridge).sriovVfHasSriovPfRelationship(any());
    // Act
    heatbridge.buildAddVserverLInterfacesToAaiAction(stackResources, Arrays.asList("1", "2"), "CloudOwner");
    // Assert
    verify(transaction, times(20)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
    verify(osClient, times(5)).getPortById(anyString());
    verify(osClient, times(5)).getSubnetById("testSubnetId");
    verify(osClient, times(10)).getNetworkById(anyString());
    verify(transaction, times(5)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
}
Also used : Optional(java.util.Optional) Port(org.openstack4j.model.network.Port) IP(org.openstack4j.model.network.IP) Resource(org.openstack4j.model.heat.Resource) HeatResource(org.openstack4j.openstack.heat.domain.HeatResource) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SriovPf(org.onap.aai.domain.yang.SriovPf) Pathed(org.onap.aaiclient.client.graphinventory.entities.Pathed) Results(org.onap.aaiclient.client.aai.entities.Results) Network(org.openstack4j.model.network.Network) List(java.util.List) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) DSLQuery(org.onap.aaiclient.client.graphinventory.entities.DSLQuery) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Subnet(org.openstack4j.model.network.Subnet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Resource

use of org.openstack4j.model.heat.Resource in project so by onap.

the class HeatBridgeImplTest method testBuildAddVserverLInterfacesToAaiAction_PortProfileNull.

@Test
public void testBuildAddVserverLInterfacesToAaiAction_PortProfileNull() throws HeatBridgeException, JsonParseException, JsonMappingException, IOException {
    // Arrange
    List<Resource> stackResources = (List<Resource>) extractTestStackResources();
    Port port = mock(Port.class);
    when(port.getId()).thenReturn("test-port-id");
    when(port.getName()).thenReturn("test-port-name");
    when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
    when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
    when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
    when(port.getDeviceId()).thenReturn("test-device-id");
    String pfPciId = "0000:08:00.0";
    Network network = mock(Network.class);
    when(network.getId()).thenReturn("test-network-id");
    when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
    when(network.getProviderSegID()).thenReturn("2345");
    when(osClient.getPortById("212a203a-9764-4f42-84ea-731536a8f13a")).thenReturn(port);
    when(osClient.getPortById("387e3904-8948-43d1-8635-b6c2042b54da")).thenReturn(port);
    when(osClient.getPortById("70a09dfd-f1c5-4bc8-bd8f-dc539b8d662a")).thenReturn(port);
    when(osClient.getPortById("12f88b4d-c8a4-4fbd-bcb4-7e36af02430b")).thenReturn(port);
    when(osClient.getPortById("c54b9f45-b413-4937-bbe4-3c8a5689cfc9")).thenReturn(port);
    when(osClient.getNetworkById(anyString())).thenReturn(network);
    PInterface pIf = mock(PInterface.class);
    when(pIf.getInterfaceName()).thenReturn("test-port-id");
    doNothing().when(heatbridge).updateSriovPfToSriovVF(any(), any());
    // Act
    heatbridge.buildAddVserverLInterfacesToAaiAction(stackResources, Arrays.asList("1", "2"), "CloudOwner");
    // Assert
    ArgumentCaptor<Optional> argument = ArgumentCaptor.forClass(Optional.class);
    verify(transaction, times(5)).createIfNotExists(any(AAIResourceUri.class), argument.capture());
    assertEquals(false, ((LInterface) argument.getValue().get()).isL2Multicasting());
    verify(osClient, times(5)).getPortById(anyString());
    verify(osClient, times(5)).getNetworkById(anyString());
}
Also used : PInterface(org.onap.aai.domain.yang.PInterface) Optional(java.util.Optional) Port(org.openstack4j.model.network.Port) Network(org.openstack4j.model.network.Network) Resource(org.openstack4j.model.heat.Resource) HeatResource(org.openstack4j.openstack.heat.domain.HeatResource) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) List(java.util.List) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)7 Resource (org.openstack4j.model.heat.Resource)7 List (java.util.List)6 Optional (java.util.Optional)6 Test (org.junit.Test)6 L3InterfaceIpv6AddressList (org.onap.aai.domain.yang.L3InterfaceIpv6AddressList)6 RelationshipList (org.onap.aai.domain.yang.RelationshipList)6 Network (org.openstack4j.model.network.Network)6 HeatResource (org.openstack4j.openstack.heat.domain.HeatResource)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)5 Port (org.openstack4j.model.network.Port)5 PInterface (org.onap.aai.domain.yang.PInterface)4 HashSet (java.util.HashSet)2 SriovPf (org.onap.aai.domain.yang.SriovPf)2 IP (org.openstack4j.model.network.IP)2 Subnet (org.openstack4j.model.network.Subnet)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 LInterface (org.onap.aai.domain.yang.LInterface)1 Results (org.onap.aaiclient.client.aai.entities.Results)1