From 161df8a94bb3b0c34ed16fd4fdba078bd1eeef9a Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:14:21 -0800 Subject: Second part of onap rename This is the second commit of the rename. The folder structure is renamed for appc-adapters and appc-config in this commit. Change-Id: Iaa2b8c937ff1ca1b5d1178128961fb115ee65d9b Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../appc/adapter/iaas/impl/TestIdentityUrl.java | 102 +++ .../adapter/iaas/impl/TestProviderAdapterImpl.java | 901 +++++++++++++++++++++ .../adapter/iaas/impl/TestProviderOperation.java | 162 ++++ .../appc/adapter/iaas/impl/TestRequestContext.java | 162 ++++ .../appc/adapter/iaas/impl/TestServiceCatalog.java | 105 +++ .../iaas/impl/TestServiceCatalogFactory.java | 89 ++ .../adapter/iaas/impl/TestServiceCatalogV2.java | 174 ++++ .../adapter/iaas/impl/TestServiceCatalogV3.java | 167 ++++ .../org/onap/appc/adapter/iaas/impl/TestVMURL.java | 130 +++ .../java/org/onap/appc/test/ExecutorHarness.java | 181 +++++ .../java/org/onap/appc/test/InterceptLogger.java | 449 ++++++++++ .../appc/adapter/iaas/impl/TestIdentityUrl.java | 102 --- .../adapter/iaas/impl/TestProviderAdapterImpl.java | 901 --------------------- .../adapter/iaas/impl/TestProviderOperation.java | 162 ---- .../appc/adapter/iaas/impl/TestRequestContext.java | 162 ---- .../appc/adapter/iaas/impl/TestServiceCatalog.java | 105 --- .../iaas/impl/TestServiceCatalogFactory.java | 89 -- .../adapter/iaas/impl/TestServiceCatalogV2.java | 174 ---- .../adapter/iaas/impl/TestServiceCatalogV3.java | 167 ---- .../appc/adapter/iaas/impl/TestVMURL.java | 130 --- .../org/openecomp/appc/test/ExecutorHarness.java | 181 ----- .../org/openecomp/appc/test/InterceptLogger.java | 449 ---------- .../resources/org/onap/appc/default.properties | 112 +++ .../org/openecomp/appc/default.properties | 112 --- 24 files changed, 2734 insertions(+), 2734 deletions(-) create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestIdentityUrl.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestProviderAdapterImpl.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestProviderOperation.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestRequestContext.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalog.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogFactory.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV2.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV3.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestVMURL.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/test/ExecutorHarness.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/test/InterceptLogger.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestIdentityUrl.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestProviderAdapterImpl.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestProviderOperation.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestRequestContext.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalog.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogFactory.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogV2.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogV3.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestVMURL.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/test/ExecutorHarness.java delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/test/InterceptLogger.java create mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/resources/org/onap/appc/default.properties delete mode 100644 appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/resources/org/openecomp/appc/default.properties (limited to 'appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test') diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestIdentityUrl.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestIdentityUrl.java new file mode 100644 index 000000000..dac22eadb --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestIdentityUrl.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + +package org.onap.appc.adapter.iaas.impl; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import java.util.Properties; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.appc.adapter.iaas.impl.IdentityURL; +import org.onap.appc.configuration.ConfigurationFactory; + +public class TestIdentityUrl { + + private static String URL; + + @BeforeClass + public static void before() { + Properties props = ConfigurationFactory.getConfiguration().getProperties(); + URL = props.getProperty(""); + } + + /** + * Test that we can parse and interpret valid URLs + */ + @Test + public void testValidURL1() { + URL = "http://192.168.1.1:5000/v2.0/"; + IdentityURL idurl = IdentityURL.parseURL(URL); + assertNotNull(idurl); + assertTrue(idurl.getScheme().equals("http")); + assertTrue(idurl.getHost().equals("192.168.1.1")); + assertTrue(idurl.getPort().equals("5000")); + assertNull(idurl.getPath()); + assertTrue(idurl.getVersion().equals("v2.0")); + assertTrue(idurl.toString().equals("http://192.168.1.1:5000/v2.0")); + } + + @Test + public void testValidURL2() { + URL = "https://192.168.1.1:5000/v3/"; + IdentityURL idurl = IdentityURL.parseURL(URL); + assertNotNull(idurl); + assertTrue(idurl.getScheme().equals("https")); + assertTrue(idurl.getHost().equals("192.168.1.1")); + assertTrue(idurl.getPort().equals("5000")); + assertNull(idurl.getPath()); + assertTrue(idurl.getVersion().equals("v3")); + assertTrue(idurl.toString().equals("https://192.168.1.1:5000/v3")); + } + + @Test + public void testValidURL3() { + URL = "http://192.168.1.1/v2.0/"; + IdentityURL idurl = IdentityURL.parseURL(URL); + assertNotNull(idurl); + assertTrue(idurl.getScheme().equals("http")); + assertTrue(idurl.getHost().equals("192.168.1.1")); + assertNull(idurl.getPort()); + assertNull(idurl.getPath()); + assertTrue(idurl.getVersion().equals("v2.0")); + System.out.println(idurl.toString()); + assertTrue(idurl.toString().equals("http://192.168.1.1/v2.0")); + } + + @Test + public void testValidURL4() { + URL = "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3"; + IdentityURL idurl = IdentityURL.parseURL(URL); + assertNotNull(idurl); + assertTrue(idurl.getScheme().equals("http")); + assertTrue(idurl.getHost().equals("msb.onap.org")); + assertTrue(idurl.getPort().equals("80")); + assertTrue(idurl.getPath().equals("/api/multicloud/v0/cloudowner_region/identity")); + assertTrue(idurl.getVersion().equals("v3")); + assertTrue(idurl.toString().equals("http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3")); + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestProviderAdapterImpl.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestProviderAdapterImpl.java new file mode 100644 index 000000000..386c1115b --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestProviderAdapterImpl.java @@ -0,0 +1,901 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.iaas.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.onap.appc.Constants; +import org.onap.appc.adapter.iaas.ProviderAdapter; +import org.onap.appc.adapter.iaas.impl.ProviderAdapterImpl; +import org.onap.appc.adapter.iaas.impl.ProviderCache; +import org.onap.appc.adapter.iaas.impl.ServiceCatalog; +import org.onap.appc.adapter.iaas.impl.TenantCache; +import org.onap.appc.adapter.iaas.impl.VMURL; +import org.onap.appc.configuration.ConfigurationFactory; +import org.onap.appc.exceptions.APPCException; +import org.onap.appc.exceptions.UnknownProviderException; +import com.att.cdp.exceptions.ZoneException; +import com.att.cdp.zones.ComputeService; +import com.att.cdp.zones.Context; +import com.att.cdp.zones.ContextFactory; +import com.att.cdp.zones.model.Image; +import com.att.cdp.zones.model.Server; +import com.att.cdp.zones.model.Server.Status; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.woorea.openstack.keystone.model.Access.Service.Endpoint; + +/** + * Test the ProviderAdapter implementation. + */ +@Category(org.onap.appc.adapter.iaas.impl.TestProviderAdapterImpl.class) +public class TestProviderAdapterImpl { + + @SuppressWarnings("nls") + private static final String PROVIDER_NAME = "ILAB"; + + @SuppressWarnings("nls") + private static final String PROVIDER_TYPE = "OpenStackProvider"; + + private static String IDENTITY_URL; + + private static String PRINCIPAL; + + private static String CREDENTIAL; + + private static String TENANT_NAME; + + private static String TENANT_ID; + + private static String USER_ID; + + private static String REGION_NAME; + + private static String SERVER_URL; + + private static Class providerAdapterImplClass; + private static Class configurationFactoryClass; + private static Field providerCacheField; + private static Field configField; + + private ProviderAdapterImpl adapter; + + /** + * Use reflection to locate fields and methods so that they can be manipulated during the test + * to change the internal state accordingly. + * + * @throws NoSuchFieldException if the field(s) dont exist + * @throws SecurityException if reflective access is not allowed + * @throws NoSuchMethodException If the method(s) dont exist + */ + @SuppressWarnings("nls") + @BeforeClass + public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException { + providerAdapterImplClass = ProviderAdapterImpl.class; + configurationFactoryClass = ConfigurationFactory.class; + + providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache"); + providerCacheField.setAccessible(true); + + configField = configurationFactoryClass.getDeclaredField("config"); + configField.setAccessible(true); + + Properties props = ConfigurationFactory.getConfiguration().getProperties(); + IDENTITY_URL = props.getProperty("provider1.identity"); + PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc"); + CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc"); + TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc"); + TENANT_ID = props.getProperty("provider1.tenant1.id", "abcde12345fghijk6789lmnopq123rst"); + REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne"); + SERVER_URL = props.getProperty("test.url"); + } + + /** + * Setup the test environment. + * + * @throws IllegalAccessException if this Field object is enforcing Java language access control + * and the underlying field is either inaccessible or final. + * @throws IllegalArgumentException if the specified object is not an instance of the class or + * interface declaring the underlying field (or a subclass or implementor thereof), or + * if an unwrapping conversion fails. + * @throws NullPointerException if the specified object is null and the field is an instance + * field. + * @throws ExceptionInInitializerError if the initialization provoked by this method fails. + */ + @Before + public void setup() throws IllegalArgumentException, IllegalAccessException { + configField.set(null, null); + Properties properties = new Properties(); + adapter = new ProviderAdapterImpl(properties); + } + + /** + * This method inspects the provider adapter implementation to make sure that the cache of + * providers and tenants, as well as the service catalog, and all pools of contexts have been + * set up correctly. + * + * @throws IllegalAccessException if this Field object is enforcing Java language access control + * and the underlying field is inaccessible. + * @throws IllegalArgumentException if the specified object is not an instance of the class or + * interface declaring the underlying field (or a subclass or implementor thereof). + */ + @SuppressWarnings({"unchecked"}) + @Ignore + @Test + public void validateCacheIsCreatedCorrectly() throws IllegalArgumentException, IllegalAccessException { + Map providerCaches = (Map) providerCacheField.get(adapter); + + assertNotNull(providerCaches); + assertEquals(1, providerCaches.size()); + assertTrue(providerCaches.containsKey(PROVIDER_NAME)); + + ProviderCache providerCache = providerCaches.get(PROVIDER_NAME); + assertEquals(PROVIDER_NAME, providerCache.getProviderName()); + assertEquals(PROVIDER_TYPE, providerCache.getProviderType()); + + Map tenantCaches = providerCache.getTenants(); + assertNotNull(tenantCaches); + assertEquals(1, tenantCaches.size()); + assertTrue(tenantCaches.containsKey(TENANT_NAME)); + + TenantCache tenantCache = tenantCaches.get(TENANT_NAME); + + assertEquals(TENANT_ID, tenantCache.getTenantId()); + assertEquals(TENANT_NAME, tenantCache.getTenantName()); + assertEquals(USER_ID, tenantCache.getUserid()); + + ServiceCatalog catalog = tenantCache.getServiceCatalog(); + assertNotNull(catalog); + + System.out.println(catalog.toString()); + List serviceTypes = catalog.getServiceTypes(); + assertNotNull(serviceTypes); + assertEquals(12, serviceTypes.size()); + + assertEquals(TENANT_NAME, catalog.getProjectName()); + assertEquals(TENANT_ID, catalog.getProjectId()); + + Set regionNames = catalog.getRegions(); + assertNotNull(regionNames); + assertEquals(1, regionNames.size()); + assertTrue(regionNames.contains(REGION_NAME)); + + List endpoints = catalog.getEndpoints(ServiceCatalog.IDENTITY_SERVICE); + assertNotNull(endpoints); + assertEquals(1, endpoints.size()); + Endpoint endpoint = (Endpoint) endpoints.get(0); + assertNotNull(endpoint); + assertEquals(REGION_NAME, endpoint.getRegion()); + assertEquals(IDENTITY_URL, endpoint.getPublicURL()); + + endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE); + assertNotNull(endpoints); + assertEquals(1, endpoints.size()); + endpoint = (Endpoint) endpoints.get(0); + assertNotNull(endpoint); + assertEquals(REGION_NAME, endpoint.getRegion()); + + endpoints = catalog.getEndpoints(ServiceCatalog.VOLUME_SERVICE); + assertNotNull(endpoints); + assertEquals(1, endpoints.size()); + endpoint = (Endpoint) endpoints.get(0); + assertNotNull(endpoint); + assertEquals(REGION_NAME, endpoint.getRegion()); + + endpoints = catalog.getEndpoints(ServiceCatalog.IMAGE_SERVICE); + assertNotNull(endpoints); + assertEquals(1, endpoints.size()); + endpoint = (Endpoint) endpoints.get(0); + assertNotNull(endpoint); + assertEquals(REGION_NAME, endpoint.getRegion()); + + endpoints = catalog.getEndpoints(ServiceCatalog.NETWORK_SERVICE); + assertNotNull(endpoints); + assertEquals(1, endpoints.size()); + endpoint = (Endpoint) endpoints.get(0); + assertNotNull(endpoint); + assertEquals(REGION_NAME, endpoint.getRegion()); + + assertTrue(catalog.isServicePublished(ServiceCatalog.IDENTITY_SERVICE)); + assertTrue(catalog.isServicePublished(ServiceCatalog.COMPUTE_SERVICE)); + assertTrue(catalog.isServicePublished(ServiceCatalog.VOLUME_SERVICE)); + assertTrue(catalog.isServicePublished(ServiceCatalog.IMAGE_SERVICE)); + assertTrue(catalog.isServicePublished(ServiceCatalog.NETWORK_SERVICE)); + } + + /** + * This test case is used to actually validate that a server has been restarted from an already + * running state + * + * @throws ZoneException If the login cannot be performed because the principal and/or + * credentials are invalid. + * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if + * the expected argument(s) are not defined or are invalid + * @throws IllegalStateException If the identity service is not available or cannot be created + * @throws IOException if an I/O error occurs + * @throws APPCException + */ + // @Ignore + @Test + public void testRestartRunningServer() + throws IllegalStateException, IllegalArgumentException, ZoneException, IOException, APPCException { + Properties properties = new Properties(); + properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); + properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); + properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); + properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + properties.setProperty(ContextFactory.PROPERTY_DISABLE_PROXY, "true"); + + try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { + context.login(PRINCIPAL, CREDENTIAL); + VMURL vm = VMURL.parseURL(SERVER_URL); + + ComputeService computeService = context.getComputeService(); + Server server = computeService.getServer(vm.getServerId()); + if (!server.getStatus().equals(Status.RUNNING)) { + server.start(); + assertTrue(waitForStateChange(server, Status.RUNNING)); + } + + Map params = new HashMap<>(); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); + params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); + SvcLogicContext svcContext = new SvcLogicContext(); + + server = adapter.restartServer(params, svcContext); + + assertEquals(Server.Status.RUNNING, server.getStatus()); + } + } + + + /****************************************/ + /** + * Tests that the vmStatuschecker method works and returns the correct status of the VM + * requested + * + * @throws ZoneException If the login cannot be performed because the principal and/or + * credentials are invalid. + * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if + * the expected argument(s) are not defined or are invalid + * @throws IllegalStateException If the identity service is not available or cannot be created + * @throws IOException if an I/O error occurs + * @throws UnknownProviderException If the provider cannot be found + */ + // @Ignore + @Test + public void testVmStatuschecker() throws IllegalStateException, IllegalArgumentException, ZoneException, + UnknownProviderException, IOException { + Properties properties = new Properties(); + properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); + properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); + properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); + properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + properties.setProperty(ContextFactory.PROPERTY_DISABLE_PROXY, "true"); + + try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { + context.login(PRINCIPAL, CREDENTIAL); + VMURL vm = VMURL.parseURL(SERVER_URL); + + ComputeService computeService = context.getComputeService(); + Server server = computeService.getServer(vm.getServerId()); + if (!server.getStatus().equals(Status.RUNNING)) { + server.start(); + assertTrue(waitForStateChange(server, Status.RUNNING)); + } + // or instead of the if-block, can ensureRunning(server) be used? + ensureRunning(server); + assertEquals(Server.Status.RUNNING, server.getStatus()); + } + } + + /****************************************/ + + + /** + * Tests that we can restart a server that is already stopped + * + * @throws ZoneException If the login cannot be performed because the principal and/or + * credentials are invalid. + * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if + * the expected argument(s) are not defined or are invalid. + * @throws IllegalStateException If the identity service is not available or cannot be created + * @throws IOException if an I/O error occurs + * @throws APPCException + */ + // @Ignore + @Test + public void testRestartStoppedServer() + throws IllegalStateException, IllegalArgumentException, ZoneException, IOException, APPCException { + Properties properties = new Properties(); + properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); + properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); + properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); + properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + + try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { + context.login(PRINCIPAL, CREDENTIAL); + VMURL vm = VMURL.parseURL(SERVER_URL); + + ComputeService computeService = context.getComputeService(); + Server server = computeService.getServer(vm.getServerId()); + if (!server.getStatus().equals(Status.READY)) { + server.stop(); + assertTrue(waitForStateChange(server, Status.READY)); + } + + Map params = new HashMap<>(); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); + params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); + SvcLogicContext svcContext = new SvcLogicContext(); + + server = adapter.restartServer(params, svcContext); + + assertEquals(Server.Status.RUNNING, server.getStatus()); + + } + } + + /** + * Tests that we can rebuild a running server (not created from a bootable volume) + * + * @throws ZoneException If the login cannot be performed because the principal and/or + * credentials are invalid. + * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if + * the expected argument(s) are not defined or are invalid. + * @throws IllegalStateException If the identity service is not available or cannot be created + * @throws UnknownProviderException If the provider cannot be found + * @throws IOException if an I/O error occurs + * @throws APPCException If the server cannot be rebuilt for some reason + */ + // @Ignore + @Test + public void testRebuildRunningServer() + throws IOException, IllegalStateException, IllegalArgumentException, ZoneException, APPCException { + Properties properties = new Properties(); + properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); + properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); + properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); + properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + + try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { + context.login(PRINCIPAL, CREDENTIAL); + VMURL vm = VMURL.parseURL(SERVER_URL); + + ComputeService computeService = context.getComputeService(); + Server server = computeService.getServer(vm.getServerId()); + ensureRunning(server); + + Map params = new HashMap<>(); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); + params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); + SvcLogicContext svcContext = new SvcLogicContext(); + + server = adapter.rebuildServer(params, svcContext); + assertTrue(waitForStateChange(server, Status.RUNNING)); + + } + } + + /** + * Tests that we can rebuild a paused server (not created from a bootable volume) + * + * @throws ZoneException If the login cannot be performed because the principal and/or + * credentials are invalid. + * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if + * the expected argument(s) are not defined or are invalid. + * @throws IllegalStateException If the identity service is not available or cannot be created + * @throws UnknownProviderException If the provider cannot be found + * @throws IOException if an I/O error occurs + * @throws APPCException If the server cannot be rebuilt for some reason + */ + // @Ignore + @Test + public void testRebuildPausedServer() + throws IOException, IllegalStateException, IllegalArgumentException, ZoneException, APPCException { + Properties properties = new Properties(); + properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); + properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); + properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); + properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + + try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { + context.login(PRINCIPAL, CREDENTIAL); + VMURL vm = VMURL.parseURL(SERVER_URL); + + ComputeService computeService = context.getComputeService(); + Server server = computeService.getServer(vm.getServerId()); + ensurePaused(server); + + Map params = new HashMap<>(); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); + params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); + SvcLogicContext svcContext = new SvcLogicContext(); + + server = adapter.rebuildServer(params, svcContext); + assertTrue(waitForStateChange(server, Status.RUNNING)); + } + } + + /** + * Tests that we can rebuild a paused server (not created from a bootable volume) + * + * @throws ZoneException If the login cannot be performed because the principal and/or + * credentials are invalid. + * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if + * the expected argument(s) are not defined or are invalid. + * @throws IllegalStateException If the identity service is not available or cannot be created + * @throws UnknownProviderException If the provider cannot be found + * @throws IOException if an I/O error occurs + * @throws APPCException If the server cannot be rebuilt for some reason + */ + // @Ignore + @Test + public void testRebuildSuspendedServer() + throws IOException, IllegalStateException, IllegalArgumentException, ZoneException, APPCException { + Properties properties = new Properties(); + properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); + properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); + properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); + properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + + try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { + context.login(PRINCIPAL, CREDENTIAL); + VMURL vm = VMURL.parseURL(SERVER_URL); + + ComputeService computeService = context.getComputeService(); + Server server = computeService.getServer(vm.getServerId()); + ensureSuspended(server); + + Map params = new HashMap<>(); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); + params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); + SvcLogicContext svcContext = new SvcLogicContext(); + + server = adapter.rebuildServer(params, svcContext); + assertTrue(waitForStateChange(server, Status.RUNNING)); + } + } + + /** + * Tests that we can rebuild a paused server (not created from a bootable volume) + * + * @throws ZoneException If the login cannot be performed because the principal and/or + * credentials are invalid. + * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if + * the expected argument(s) are not defined or are invalid. + * @throws IllegalStateException If the identity service is not available or cannot be created + * @throws UnknownProviderException If the provider cannot be found + * @throws IOException if an I/O error occurs + * @throws APPCException If the server cannot be rebuilt for some reason + */ + // @Ignore + @Test + public void testRebuildStoppedServer() + throws IOException, IllegalStateException, IllegalArgumentException, ZoneException, APPCException { + Properties properties = new Properties(); + properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); + properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); + properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); + properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + + try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { + context.login(PRINCIPAL, CREDENTIAL); + VMURL vm = VMURL.parseURL(SERVER_URL); + + ComputeService computeService = context.getComputeService(); + Server server = computeService.getServer(vm.getServerId()); + ensureStopped(server); + + Map params = new HashMap<>(); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); + params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); + SvcLogicContext svcContext = new SvcLogicContext(); + + server = adapter.rebuildServer(params, svcContext); + assertTrue(waitForStateChange(server, Status.RUNNING)); + } + } + + /** + * Test subsequent action on second vm in different Tenant resulting in {"itemNotFound": + * {"message": "Instance could not be found", "code": 404}} + * + * @throws ZoneException If the login cannot be performed because the principal and/or + * credentials are invalid. + * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if + * the expected argument(s) are not defined or are invalid + * @throws IllegalStateException If the identity service is not available or cannot be created + * @throws IOException if an I/O error occurs + * @throws APPCException + */ + + @Test + public void testTenantVerification() + throws IllegalStateException, IllegalArgumentException, ZoneException, IOException, APPCException { + + Properties properties = new Properties(); + properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, "http://example.com:5000"); + properties.setProperty(ContextFactory.PROPERTY_TENANT, "APP-C"); + properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + + String vmUrl = + "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; + + // try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { + // context.login("AppC", "AppC"); + + // call lookupServer on vm in defined tenant "APP-C_TLV" + VMURL vm = VMURL.parseURL(vmUrl); + + Map params = new HashMap<>(); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, vmUrl); + params.put(ProviderAdapter.PROPERTY_IDENTITY_URL, "http://example.com:5000/v2.0"); + params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, "http://example.com:5000/v2.0"); + SvcLogicContext svcContext = new SvcLogicContext(); + + long start, end = 0; + + System.out.println("\n--------------------Begin lookupServer on tenant 1--------------------"); + start = System.currentTimeMillis(); + Server server = adapter.lookupServer(params, svcContext); + end = System.currentTimeMillis(); + + System.out.println(String.format("lookupServer on tenant 1 took %ds", (end - start) / 1000)); + System.out.println("----------------------------------------------------------------------\n"); + assertNotNull(server); + + // repeat to show that context is reused for second request + System.out.println("\n-----------------Begin repeat lookupServer on tenant 1----------------"); + start = System.currentTimeMillis(); + server = adapter.lookupServer(params, svcContext); + end = System.currentTimeMillis(); + + System.out.println(String.format("Repeat lookupServer on tenant 1 took %ds", (end - start) / 1000)); + System.out.println("----------------------------------------------------------------------\n"); + assertNotNull(server); + + // call lookupServer on vm in second tenant "Play" + // This is where we would fail due to using the previous + // tenants context + vmUrl = "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; + vm = VMURL.parseURL(vmUrl); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, vmUrl); + + System.out.println("\n--------------------Begin lookupServer on tenant 2--------------------"); + start = System.currentTimeMillis(); + server = adapter.lookupServer(params, svcContext); + end = System.currentTimeMillis(); + System.out.println(String.format("\nlookupServer on tenant 2 took %ds", (end - start) / 1000)); + System.out.println("----------------------------------------------------------------------\n"); + assertNotNull(server); + + // call lookupServer on vm in non-existing tenant + vmUrl = "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; + vm = VMURL.parseURL(vmUrl); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, vmUrl); + + System.out.println("\n--------------Begin lookupServer on non-existant tenant--------------"); + start = System.currentTimeMillis(); + server = adapter.lookupServer(params, svcContext); + end = System.currentTimeMillis(); + System.out.println(String.format("\nlookupServer on tenant 3 took %ds", (end - start) / 1000)); + System.out.println("----------------------------------------------------------------------\n"); + assertNull(server); + + // } + } + + /****************************************/ + + + @Test + public void testSnapshotServer() throws Exception { + Properties properties = new Properties(); + properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, "http://example.com:5000"); + // properties.setProperty(ContextFactory.PROPERTY_REGION, ""); + properties.setProperty(ContextFactory.PROPERTY_TENANT, "Play"); + properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + + String vmUrl = + "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; + + try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { + context.login("AppC", "AppC"); + VMURL vm = VMURL.parseURL(vmUrl); + + Map params = new HashMap<>(); + params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, vmUrl); + params.put(ProviderAdapter.PROPERTY_IDENTITY_URL, "http://example.com:5000/v2.0"); + params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, "http://example.com:5000/v2.0"); + SvcLogicContext svcContext = new SvcLogicContext(); + + long start, end = 0; + + start = System.currentTimeMillis(); + Image image = adapter.createSnapshot(params, svcContext); + end = System.currentTimeMillis(); + + System.out.println(String.format("Image ID: %s", image.getId())); + System.out.println(String.format("Snapshot took %ds", (end - start) / 1000)); + + start = System.currentTimeMillis(); + adapter.rebuildServer(params, svcContext); + end = System.currentTimeMillis(); + System.out.println(String.format("Rebuild took %ds", (end - start) / 1000)); + } + + } + + /** + * Ensures that the server is in stopped (shutdown) state prior to test + * + * @param server The server to ensure is stopped + * @throws ZoneException If the server can't be operated upon for some reason + */ + @SuppressWarnings("nls") + private static void ensureStopped(Server server) throws ZoneException { + switch (server.getStatus()) { + case READY: + break; + + case PENDING: + waitForStateChange(server, Server.Status.READY, Server.Status.RUNNING, Server.Status.PAUSED, + Server.Status.SUSPENDED, Server.Status.ERROR); + ensureSuspended(server); + break; + + case PAUSED: + server.unpause(); + waitForStateChange(server, Server.Status.RUNNING); + server.stop(); + waitForStateChange(server, Server.Status.READY); + break; + + case SUSPENDED: + server.resume(); + waitForStateChange(server, Server.Status.RUNNING); + server.stop(); + waitForStateChange(server, Server.Status.READY); + break; + + case RUNNING: + server.stop(); + waitForStateChange(server, Server.Status.READY); + break; + + case DELETED: + case ERROR: + default: + fail("Server state is not valid for test - " + server.getStatus().name()); + } + } + + /** + * Ensures that the server is in suspended state prior to test + * + * @param server The server to ensure is suspended + * @throws ZoneException If the server can't be operated upon for some reason + */ + @SuppressWarnings("nls") + private static void ensureSuspended(Server server) throws ZoneException { + switch (server.getStatus()) { + case SUSPENDED: + break; + + case PENDING: + waitForStateChange(server, Server.Status.READY, Server.Status.RUNNING, Server.Status.PAUSED, + Server.Status.SUSPENDED, Server.Status.ERROR); + ensureSuspended(server); + break; + + case PAUSED: + server.unpause(); + waitForStateChange(server, Server.Status.RUNNING); + server.suspend(); + waitForStateChange(server, Server.Status.SUSPENDED); + break; + + case READY: + server.start(); + waitForStateChange(server, Server.Status.RUNNING); + server.suspend(); + waitForStateChange(server, Server.Status.SUSPENDED); + break; + + case RUNNING: + server.suspend(); + waitForStateChange(server, Server.Status.SUSPENDED); + break; + + case DELETED: + case ERROR: + default: + fail("Server state is not valid for test - " + server.getStatus().name()); + } + } + + /** + * This method makes sure that the indicated server is running before performing a test + * + * @param server The server to ensure is running + * @throws ZoneException If the server can't be operated upon + */ + @SuppressWarnings("nls") + private static void ensureRunning(Server server) throws ZoneException { + switch (server.getStatus()) { + case RUNNING: + break; + + case PENDING: + waitForStateChange(server, Server.Status.READY, Server.Status.RUNNING, Server.Status.PAUSED, + Server.Status.SUSPENDED, Server.Status.ERROR); + ensureRunning(server); + break; + + case PAUSED: + server.unpause(); + waitForStateChange(server, Server.Status.RUNNING); + break; + + case SUSPENDED: + server.resume(); + waitForStateChange(server, Server.Status.RUNNING); + break; + + case READY: + server.start(); + waitForStateChange(server, Server.Status.RUNNING); + break; + + case DELETED: + case ERROR: + default: + fail("Server state is not valid for test - " + server.getStatus().name()); + } + } + + /** + * This method will make sure that the server we are testing is paused + * + * @param server The server to make sure is paused for the test + * @throws ZoneException If anything fails + */ + @SuppressWarnings("nls") + private static void ensurePaused(Server server) throws ZoneException { + switch (server.getStatus()) { + case PAUSED: + break; + + case PENDING: + waitForStateChange(server, Server.Status.READY, Server.Status.RUNNING, Server.Status.PAUSED, + Server.Status.SUSPENDED, Server.Status.ERROR); + ensurePaused(server); + break; + + case READY: + server.start(); + waitForStateChange(server, Server.Status.RUNNING); + server.pause(); + waitForStateChange(server, Server.Status.PAUSED); + break; + + case RUNNING: + server.pause(); + waitForStateChange(server, Server.Status.PAUSED); + break; + + case SUSPENDED: + server.resume(); + waitForStateChange(server, Server.Status.RUNNING); + server.pause(); + waitForStateChange(server, Server.Status.PAUSED); + break; + + case ERROR: + case DELETED: + default: + fail("Server state is not valid for test - " + server.getStatus().name()); + } + } + + /** + * Enter a pool-wait loop checking the server state to see if it has entered one of the desired + * states or not. + *

+ * This method checks the state of the server periodically for one of the desired states. When + * the server enters one of the desired states, the method returns a successful indication + * (true). If the server never enters one of the desired states within the alloted timeout + * period, then the method returns a failed response (false). No exceptions are thrown from this + * method. + *

+ * + * @param server The server to wait on + * @param desiredStates A variable list of desired states, any one of which is allowed. + * @return True if the server entered one of the desired states, and false if not and the wait + * loop timed out. + */ + private static boolean waitForStateChange(Server server, Server.Status... desiredStates) { + int timeout = ConfigurationFactory.getConfiguration() + .getIntegerProperty(Constants.PROPERTY_SERVER_STATE_CHANGE_TIMEOUT); + long limit = System.currentTimeMillis() + (timeout * 1000); + Server vm = server; + + try { + while (limit > System.currentTimeMillis()) { + vm.refresh(); + for (Server.Status desiredState : desiredStates) { + if (server.getStatus().equals(desiredState)) { + return true; + } + } + + try { + Thread.sleep(10000L); + } catch (InterruptedException e) { + // ignore + } + } + } catch (ZoneException e) { + e.printStackTrace(); + } + + return false; + } + + /* + * @Test public void testTerminateStack() throws IllegalStateException, + * IllegalArgumentException, ZoneException, UnknownProviderException, IOException { Properties + * properties = new Properties(); properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, + * IDENTITY_URL); properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); + * properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); + * properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); + * properties.setProperty(ContextFactory.PROPERTY_DISABLE_PROXY, "true"); try (Context context = + * ContextFactory.getContext(PROVIDER_TYPE, properties)) { context.login(PRINCIPAL, CREDENTIAL); + * VMURL vm = VMURL.parseURL(SERVER_URL); ComputeService computeService = + * context.getComputeService(); Server server = computeService.getServer(vm.getServerId()); if + * (!server.getStatus().equals(Status.RUNNING)) { server.start(); + * assertTrue(waitForStateChange(server, Status.RUNNING)); } Map params = new + * HashMap<>(); params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); + * params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); SvcLogicContext svcContext + * = new SvcLogicContext(); Stack stack = adapter.terminateStack(params, svcContext); + * assertNotNull(stack); } } + */ + +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestProviderOperation.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestProviderOperation.java new file mode 100644 index 000000000..c080cf953 --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestProviderOperation.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.iaas.impl; + +import java.lang.reflect.Field; +import java.util.Map; +import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation; +import org.onap.appc.exceptions.APPCException; +import com.att.cdp.zones.model.ModelObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.MDC; +import org.onap.appc.configuration.ConfigurationFactory; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import static org.onap.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE; + +/** + * This class is used to test methods and functions of the adapter implementation that do not + * require and do not set up connections to any providers. + * + * @since Jan 20, 2016 + * @version $Id$ + */ + +public class TestProviderOperation extends ProviderOperation { + + private static Class providerAdapterImplClass; + private static Class configurationFactoryClass; + private static Field providerCacheField; + private static Field configField; + + /** + * Use reflection to locate fields and methods so that they can be manipulated during the test + * to change the internal state accordingly. + * + * @throws NoSuchFieldException if the field(s) dont exist + * @throws SecurityException if reflective access is not allowed + * @throws NoSuchMethodException If the method(s) dont exist + */ + @SuppressWarnings("nls") + @BeforeClass + public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException { + providerAdapterImplClass = ProviderAdapterImpl.class; + configurationFactoryClass = ConfigurationFactory.class; + + providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache"); + providerCacheField.setAccessible(true); + + configField = configurationFactoryClass.getDeclaredField("config"); + configField.setAccessible(true); + } + + /** + * This test expects a failure because the value to be validated is a null URL + * + * @throws RequestFailedException Expected + */ + @SuppressWarnings("nls") + @Test(expected = RequestFailedException.class) + public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException { + MDC.put(MDC_SERVICE, "junit"); + SvcLogicContext svcContext = new SvcLogicContext(); + RequestContext rc = new RequestContext(svcContext); + String link = null; + + validateVMURL(VMURL.parseURL(link)); + } + + /** + * This test expects a failure because the value to be validated is an empty URL + * + * @throws RequestFailedException Expected + */ + @SuppressWarnings("nls") + @Test(expected = RequestFailedException.class) + public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException { + MDC.put(MDC_SERVICE, "junit"); + SvcLogicContext svcContext = new SvcLogicContext(); + RequestContext rc = new RequestContext(svcContext); + String link = ""; + + validateVMURL(VMURL.parseURL(link)); + } + + /** + * This test expects a failure because the value to be validated is a blank URL + * + * @throws RequestFailedException Expected + */ + @SuppressWarnings("nls") + @Test(expected = RequestFailedException.class) + public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException { + MDC.put(MDC_SERVICE, "junit"); + SvcLogicContext svcContext = new SvcLogicContext(); + RequestContext rc = new RequestContext(svcContext); + String link = " "; + + validateVMURL(VMURL.parseURL(link)); + } + + /** + * This test expects a failure because the value to be validated is a bad URL + * + * @throws RequestFailedException Expected + */ + @SuppressWarnings("nls") + @Test(expected = RequestFailedException.class) + public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException { + MDC.put(MDC_SERVICE, "junit"); + SvcLogicContext svcContext = new SvcLogicContext(); + RequestContext rc = new RequestContext(svcContext); + String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/"; + + validateVMURL(VMURL.parseURL(link)); + } + + /** + * This test expects to pass + * + * @throws RequestFailedException Un-Expected + */ + @SuppressWarnings("nls") + @Test + public void testValidateParameterPatternValidURL() throws RequestFailedException { + MDC.put(MDC_SERVICE, "junit"); + SvcLogicContext svcContext = new SvcLogicContext(); + RequestContext rc = new RequestContext(svcContext); + String link = + "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551"; + + validateVMURL(VMURL.parseURL(link)); + } + + @Override + protected ModelObject executeProviderOperation(Map params, SvcLogicContext context) + throws APPCException { + return null; + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestRequestContext.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestRequestContext.java new file mode 100644 index 000000000..7ea30635c --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestRequestContext.java @@ -0,0 +1,162 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + +package org.onap.appc.adapter.iaas.impl; + +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; +import org.onap.appc.Constants; +import org.onap.appc.adapter.iaas.impl.RequestContext; +import org.onap.appc.configuration.Configuration; +import org.onap.appc.configuration.ConfigurationFactory; + +/** + * Test the RequestContext object + *

+ * The request context is used to track retries, recovery attempts, and time to live of the + * processing of a request. + *

+ */ + +public class TestRequestContext { + + private RequestContext rc; + private Configuration config = ConfigurationFactory.getConfiguration(); + + /** + * Set up the test environment by forcing the retry delay and limit to small values for the test + * and setting up the request context object. + */ + @Before + public void setup() { + config.setProperty(Constants.PROPERTY_RETRY_DELAY, "1"); + config.setProperty(Constants.PROPERTY_RETRY_LIMIT, "3"); + rc = new RequestContext(null); + rc.setTimeToLiveSeconds(2); + } + + /** + * Ensure that we set up the property correctly + */ + @Test + public void testRetryDelayProperty() { + assertEquals(1, rc.getRetryDelay()); + } + + /** + * Ensure that we set up the property correctly + */ + @Test + public void testRetryLimitProperty() { + assertEquals(3, rc.getRetryLimit()); + } + + /** + * This test ensures that the retry attempt counter is zero on a new context + */ + @Test + public void testRetryCountNoRetries() { + assertEquals(0, rc.getAttempts()); + } + + /** + * Test that the delay is accurate + */ + @Test + public void testDelay() { + long future = System.currentTimeMillis() + (rc.getRetryDelay() * 1000L); + + rc.delay(); + + assertTrue(System.currentTimeMillis() >= future); + } + + /** + * The RequestContext tracks the number of retry attempts against the limit. This test verifies + * that tracking logic works correctly. + */ + @Test + public void testCanRetry() { + assertEquals(0, rc.getAttempts()); + assertTrue(rc.attempt()); + assertEquals(1, rc.getAttempts()); + assertTrue(rc.attempt()); + assertEquals(2, rc.getAttempts()); + assertTrue(rc.attempt()); + assertEquals(3, rc.getAttempts()); + assertFalse(rc.attempt()); + assertEquals(3, rc.getAttempts()); + assertFalse(rc.attempt()); + assertEquals(3, rc.getAttempts()); + assertFalse(rc.attempt()); + assertEquals(3, rc.getAttempts()); + } + + /** + * The same RequestContext is used throughout the processing, and retries need to be reset once + * successfully connected so that any earlier (successful) recoveries are not considered when + * performing any new future recoveries. This test ensures that a reset clears the retry counter + * and that we can attempt retries again up to the limit. + */ + @Test + public void testResetAndCanRetry() { + assertTrue(rc.attempt()); + assertTrue(rc.attempt()); + assertTrue(rc.attempt()); + rc.reset(); + + assertTrue(rc.attempt()); + assertTrue(rc.attempt()); + assertTrue(rc.attempt()); + assertFalse(rc.attempt()); + assertFalse(rc.attempt()); + assertFalse(rc.attempt()); + } + + /** + * This test is used to test tracking of time to live for the request context. Because time is + * inexact, the assertions can only be ranges of values, such as at least some value or greater. + * The total duration tracking in the request context is only updated on each call to + * {@link RequestContext#isAlive()}. Also, durations are NOT affected by calls to reset. + */ + @Test + public void testTimeToLive() { + assertTrue(rc.getTotalDuration() == 0L); + assertTrue(rc.isAlive()); + rc.reset(); + rc.delay(); + assertTrue(rc.isAlive()); + assertTrue(rc.getTotalDuration() >= 1000L); + rc.reset(); + rc.delay(); + rc.isAlive(); + assertTrue(rc.getTotalDuration() >= 2000L); + rc.reset(); + rc.delay(); + assertFalse(rc.isAlive()); + assertTrue(rc.getTotalDuration() >= 3000L); + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalog.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalog.java new file mode 100644 index 000000000..c1a41f209 --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalog.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + + +package org.onap.appc.adapter.iaas.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.appc.configuration.ConfigurationFactory; +import com.att.cdp.exceptions.ZoneException; +import com.woorea.openstack.keystone.model.Access.Service; + +/** + * This class tests the service catalog against a known provider. + */ +public class TestServiceCatalog { + + // Number + private static int EXPECTED_REGIONS = 2; + private static int EXPECTED_ENDPOINTS = 1; + + private static String PRINCIPAL; + private static String CREDENTIAL; + private static String TENANT_NAME; + private static String TENANT_ID; + private static String IDENTITY_URL; + private static String REGION_NAME; + + private ServiceCatalog catalog; + + private Properties properties; + + @BeforeClass + public static void before() { + Properties props = ConfigurationFactory.getConfiguration().getProperties(); + IDENTITY_URL = props.getProperty("provider1.identity"); + PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc"); + CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc"); + TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc"); + TENANT_ID = props.getProperty("provider1.tenant1.id", + props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst")); + REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne"); + + EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "2")); + EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0")); + } + + /** + * Setup the test environment by loading a new service catalog for each test + * + * @throws ZoneException + */ + @Before + public void setup() throws ZoneException { + properties = new Properties(); + catalog = Mockito.mock(ServiceCatalog.class, Mockito.CALLS_REAL_METHODS); + catalog.rwLock = new ReentrantReadWriteLock(); + + Set testdata = new HashSet<>(); + testdata.add("RegionOne"); + catalog.regions = testdata; + } + + /** + * Test that we find all of the expected region(s) + */ + @Test + public void testKnownRegions() { + assertEquals(EXPECTED_REGIONS, catalog.getRegions().size()); + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogFactory.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogFactory.java new file mode 100644 index 000000000..e974d27ba --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogFactory.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.iaas.impl; + +import java.util.Properties; +import org.junit.Assert; +import org.junit.Test; + +public class TestServiceCatalogFactory { + + @Test + public void testGetServiceCatalogV2() { + String tenantIdentifier = null; + String principal = null; + String credential = null; + String domain = null; + Properties properties = null; + + String url = "http://192.168.1.1:5000/v2.0/"; + ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, + domain, properties); + Assert.assertNotNull(catalog); + Assert.assertEquals(catalog.getClass(), ServiceCatalogV2.class); + + url = "http://192.168.1.1:5000/v2/"; + catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, domain, + properties); + Assert.assertNotNull(catalog); + Assert.assertEquals(catalog.getClass(), ServiceCatalogV2.class); + + url = "http://192.168.1.1:5000/v2.1/"; + catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, domain, + properties); + Assert.assertNotNull(catalog); + Assert.assertEquals(catalog.getClass(), ServiceCatalogV2.class); + + } + + @Test + public void testGetServiceCatalogV3() { + String url = "http://192.168.1.1:5000/v3.0/"; + String tenantIdentifier = null; + String principal = null; + String credential = null; + String domain = null; + Properties properties = null; + ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, + domain, properties); + + Assert.assertNotNull(catalog); + Assert.assertEquals(catalog.getClass(), ServiceCatalogV3.class); + } + + @Test + public void testGetServiceCatalogOther() { + String url = "http://192.168.1.1:5000/v4.0/"; + String tenantIdentifier = null; + String principal = null; + String credential = null; + String domain = null; + Properties properties = null; + ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, + domain, properties); + + Assert.assertNull(catalog); + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV2.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV2.java new file mode 100644 index 000000000..58b56e06f --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV2.java @@ -0,0 +1,174 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.adapter.iaas.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import com.att.cdp.exceptions.ZoneException; +import com.woorea.openstack.keystone.model.Access.Service; +import java.util.List; +import java.util.Properties; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.appc.configuration.ConfigurationFactory; + +/** + * This class tests the service catalog against a known provider. + */ +@Ignore +public class TestServiceCatalogV2 { + + // Number + private static int EXPECTED_REGIONS = 1; + private static int EXPECTED_ENDPOINTS = 1; + + private static String PRINCIPAL; + private static String CREDENTIAL; + private static String TENANT_NAME; + private static String TENANT_ID; + private static String IDENTITY_URL; + private static String REGION_NAME; + + private ServiceCatalogV2 catalog; + + private Properties properties; + + @BeforeClass + public static void before() { + Properties props = ConfigurationFactory.getConfiguration().getProperties(); + IDENTITY_URL = props.getProperty("provider1.identity", "appc"); + PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc"); + CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc"); + TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc"); + TENANT_ID = props.getProperty("provider1.tenant1.id", + props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst")); + REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne"); + + EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0")); + EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0")); + } + + /** + * Setup the test environment by loading a new service catalog for each test + * + * @throws ZoneException + */ + @Before + public void setup() throws ZoneException { + properties = new Properties(); + catalog = new ServiceCatalogV2(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties); + catalog.init(); + } + + /** + * Test that the tenant name and ID are returned correctly + */ + @Test + public void testKnownTenant() { + assertEquals(TENANT_NAME, catalog.getProjectName()); + assertEquals(TENANT_ID, catalog.getProjectId()); + } + + /** + * Test that we find all of the expected region(s) + */ + @Test + public void testKnownRegions() { + assertEquals(EXPECTED_REGIONS, catalog.getRegions().size()); + // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]); + } + + /** + * Test that we can check for published services correctly + */ + @Test + public void testServiceTypesPublished() { + assertTrue(catalog.isServicePublished("compute")); + assertFalse(catalog.isServicePublished("bogus")); + } + + /** + * Check that we can get the list of published services + */ + @Test + public void testPublishedServicesList() { + // List services = catalog.getServiceTypes(); + + // assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE)); + // assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE)); + // assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE)); + // assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE)); + // assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE)); + } + + /** + * Test that we can get the endpoint(s) for a service + */ + @Test + public void testEndpointList() { + List endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE); + + assertNotNull(endpoints); + assertFalse(endpoints.isEmpty()); + assertEquals(EXPECTED_ENDPOINTS, endpoints.size()); + + Service.Endpoint endpoint = endpoints.get(0); + // assertEquals(REGION_NAME, endpoint.getRegion()); + } + + @Test + public void testToString() { + String testString = catalog.toString(); + assertNotNull(testString); + } + + @Ignore + @Test + public void liveConnectionTest() { + // this test should only be used by developers when testing against a live Openstack + // instance, otherwise it should be ignored + properties = new Properties(); + String identity = "http://192.168.0.1:5000/v2.0"; + String tenantName = "Tenant"; + String user = "user"; + String pass = "pass"; + + ServiceCatalogV2 catalog = new ServiceCatalogV2(identity, tenantName, user, pass, properties); + + try { + catalog.init(); + } catch (ZoneException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + String out = catalog.toString(); + System.out.println(out); + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV3.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV3.java new file mode 100644 index 000000000..26a4d7dbf --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestServiceCatalogV3.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + + +package org.onap.appc.adapter.iaas.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import com.att.cdp.exceptions.ZoneException; +import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint; +import java.util.List; +import java.util.Properties; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.appc.configuration.ConfigurationFactory; + +/** + * This class tests the service catalog against a known provider. + */ +@Ignore +public class TestServiceCatalogV3 { + + // Number + private static int EXPECTED_REGIONS = 1; + private static int EXPECTED_ENDPOINTS = 1; + + private static String PRINCIPAL; + private static String CREDENTIAL; + private static String DOMAIN; + private static String TENANT_NAME; + private static String TENANT_ID; + private static String IDENTITY_URL; + private static String REGION_NAME; + + private ServiceCatalogV3 catalog; + + private Properties properties; + + @BeforeClass + public static void before() { + Properties props = ConfigurationFactory.getConfiguration().getProperties(); + IDENTITY_URL = props.getProperty("provider1.identity"); + PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc"); + CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc"); + DOMAIN = props.getProperty("provider1.tenant1.domain", "Default"); + TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc"); + TENANT_ID = props.getProperty("provider1.tenant1.id", + props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst")); + REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne"); + + EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0")); + EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0")); + } + + /** + * Setup the test environment by loading a new service catalog for each test + * + * @throws ZoneException + */ + @Before + public void setup() throws ZoneException { + properties = new Properties(); + catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties); + } + + /** + * Test that the tenant name and ID are returned correctly + */ + @Test + public void testKnownTenant() { + assertEquals(TENANT_NAME, catalog.getProjectName()); + assertEquals(TENANT_ID, catalog.getProjectId()); + } + + /** + * Test that we find all of the expected region(s) + */ + @Test + public void testKnownRegions() { + assertEquals(EXPECTED_REGIONS, catalog.getRegions().size()); + // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]); + } + + /** + * Test that we can check for published services correctly + */ + @Test + public void testServiceTypesPublished() { + assertTrue(catalog.isServicePublished("compute")); + assertFalse(catalog.isServicePublished("bogus")); + } + + /** + * Check that we can get the list of published services + */ + @Test + public void testPublishedServicesList() { + List services = catalog.getServiceTypes(); + + assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE)); + assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE)); + assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE)); + assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE)); + assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE)); + } + + /** + * Test that we can get the endpoint(s) for a service + */ + @Test + public void testEndpointList() { + List endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE); + + assertNotNull(endpoints); + assertFalse(endpoints.isEmpty()); + assertEquals(EXPECTED_ENDPOINTS, endpoints.size()); + + Endpoint endpoint = endpoints.get(0); + // assertEquals(REGION_NAME, endpoint.getRegion()); + } + + @Test + public void testToString() { + String testString = catalog.toString(); + assertNotNull(testString); + } + + @Ignore + @Test + public void liveConnectionTest() { + // this test should only be used by developers when testing against a live Openstack + // instance, otherwise it should be ignored + properties = new Properties(); + String identity = ""; + String tenantName = ""; + String user = ""; + String pass = ""; + + catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties); + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestVMURL.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestVMURL.java new file mode 100644 index 000000000..d433afb64 --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/adapter/iaas/impl/TestVMURL.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + + +package org.onap.appc.adapter.iaas.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import java.util.Properties; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.appc.adapter.iaas.impl.VMURL; +import org.onap.appc.configuration.ConfigurationFactory; + +public class TestVMURL { + + private static String IP; + private static String PORT; + private static String TENANTID; + private static String VMID; + private static String URL; + + @BeforeClass + public static void before() { + Properties props = ConfigurationFactory.getConfiguration().getProperties(); + IP = props.getProperty("test.ip"); + PORT = props.getProperty("test.port"); + TENANTID = props.getProperty("test.tenantid"); + VMID = props.getProperty("test.vmid"); + } + + /** + * Test that we can parse and interpret valid URLs + */ + @Test + public void testValidURL1() { + URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID); + VMURL url = VMURL.parseURL(URL); + + assertEquals("http", url.getScheme()); + assertEquals(IP, url.getHost()); + assertEquals(PORT, url.getPort()); + assertEquals(TENANTID, url.getTenantId()); + assertEquals(VMID, url.getServerId()); + assertEquals(url.toString(), URL); + } + + @Test + public void testValidURL2() { + URL = String.format("http://%s/v2/%s/servers/%s", IP, TENANTID, VMID); + VMURL url = VMURL.parseURL(URL); + assertEquals("http", url.getScheme()); + assertEquals(IP, url.getHost()); + assertNull(url.getPort()); + assertNull(url.getPath()); + assertEquals(TENANTID, url.getTenantId()); + assertEquals(VMID, url.getServerId()); + assertEquals(url.toString(), URL); + } + + @Test + public void testValidURL3() { + URL = "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; + VMURL url = VMURL.parseURL(URL); + assertNotNull(url); + assertEquals("http", url.getScheme()); + assertEquals("msb.onap.org", url.getHost()); + assertEquals("80", url.getPort()); + assertEquals("/api/multicloud/v0/cloudowner_region", url.getPath()); + assertEquals(TENANTID, url.getTenantId()); + assertEquals(VMID, url.getServerId()); + assertEquals(url.toString(), URL); + } + + /** + * Test that we ignore and return null for invalid URLs + */ + @Test + public void testInvalidURLs() { + VMURL url = VMURL.parseURL(null); + assertNull(url); + + url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID)); + assertNull(url); + + url = VMURL.parseURL(String.format("http:/%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID)); + assertNull(url); + + url = VMURL.parseURL(String.format("http:///%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID)); + assertNull(url); + + url = VMURL.parseURL(String.format("http://v2/%s/servers/%s", TENANTID, VMID)); + assertNull(url); + + url = VMURL.parseURL(String.format("%s:%s/%s/servers/%s", IP, PORT, TENANTID, VMID)); + assertNull(url); + + url = VMURL.parseURL(String.format("%s:%s/v2/servers/%s", IP, PORT, VMID)); + assertNull(url); + + url = VMURL.parseURL(String.format("%s:%s/v2/%s/%s", IP, PORT, TENANTID, VMID)); + assertNull(url); + + url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers", IP, PORT, TENANTID)); + assertNull(url); + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/test/ExecutorHarness.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/test/ExecutorHarness.java new file mode 100644 index 000000000..7a03a8d84 --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/test/ExecutorHarness.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + + +package org.onap.appc.test; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.onap.appc.test.InterceptLogger; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; + +/** + * This class is used as a test harness to wrap the call to an executor node. + */ + +public class ExecutorHarness { + + /** + * The executor to be tested + */ + private SvcLogicJavaPlugin executor; + + /** + * The collection of all exec methods found on the class + */ + private Map methods; + + /** + * The field of the class being tested that contains the reference to the logger to be used. + * This is modified to point to our interception logger for the test. + */ + private Field contextLogger; + + /** + * The interception logger that buffers all messages logged and allows us to look at them as + * part of the test case. + */ + private InterceptLogger logger; + + /** + * Create the harness and initialize it + * + * @throws SecurityException If a security manager, s, is present and any of the following + * conditions is met: + *
    + *
  • invocation of s.checkMemberAccess(this, Member.DECLARED) denies access to the + * declared field
  • + *
  • the caller's class loader is not the same as or an ancestor of the class loader + * for the current class and invocation of s.checkPackageAccess() denies access to the + * package of this class
  • + *
+ * @throws NoSuchFieldException if a field with the specified name is not found. + * @throws IllegalAccessException if this Field object is enforcing Java language access control + * and the underlying field is either inaccessible or final. + * @throws IllegalArgumentException if the specified object is not an instance of the class or + * interface declaring the underlying field (or a subclass or implementor thereof), or + * if an unwrapping conversion fails. + */ + @SuppressWarnings("nls") + public ExecutorHarness() + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + methods = new HashMap<>(); + new SvcLogicContext(); + + Class contextClass = SvcLogicContext.class; + contextLogger = contextClass.getDeclaredField("LOG"); + contextLogger.setAccessible(true); + logger = new InterceptLogger(); + contextLogger.set(null, logger); + } + + /** + * Convenience constructor + * + * @param executor The executor to be tested by the harness + * @throws SecurityException If a security manager, s, is present and any of the following + * conditions is met: + *
    + *
  • invocation of s.checkMemberAccess(this, Member.DECLARED) denies access to the + * declared field
  • + *
  • the caller's class loader is not the same as or an ancestor of the class loader + * for the current class and invocation of s.checkPackageAccess() denies access to the + * package of this class
  • + *
+ * @throws NoSuchFieldException if a field with the specified name is not found. + * @throws IllegalAccessException if this Field object is enforcing Java language access control + * and the underlying field is either inaccessible or final. + * @throws IllegalArgumentException if the specified object is not an instance of the class or + * interface declaring the underlying field (or a subclass or implementor thereof), or + * if an unwrapping conversion fails. + */ + public ExecutorHarness(SvcLogicJavaPlugin executor) + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + this(); + setExecutor(executor); + } + + /** + * @param executor The java plugin class to be executed + */ + public void setExecutor(SvcLogicJavaPlugin executor) { + this.executor = executor; + scanExecutor(); + } + + /** + * @return The java plugin class to be executed + */ + public SvcLogicJavaPlugin getExecutor() { + return executor; + } + + /** + * @return The set of all methods that meet the signature requirements + */ + public List getExecMethodNames() { + List names = new ArrayList<>(); + names.addAll(methods.keySet()); + return names; + } + + /** + * Returns an indication if the named method is a valid executor method that could be called + * from a DG execute node + * + * @param methodName The method name to be validated + * @return True if the method name meets the signature requirements, false if the method either + * does not exist or does not meet the requirements. + */ + public boolean isExecMethod(String methodName) { + return methods.containsKey(methodName); + } + + /** + * This method scans the executor class hierarchy to locate all methods that match the required + * signature of the executor and records these methods in a map. + */ + private void scanExecutor() { + methods.clear(); + Class executorClass = executor.getClass(); + Method[] publicMethods = executorClass.getMethods(); + for (Method method : publicMethods) { + if (method.getReturnType().equals(Void.class)) { + Class[] paramTypes = method.getParameterTypes(); + if (paramTypes.length == 2) { + if (Map.class.isAssignableFrom(paramTypes[0]) + && SvcLogicContext.class.isAssignableFrom(paramTypes[1])) { + methods.put(method.getName(), method); + } + } + } + } + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/test/InterceptLogger.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/test/InterceptLogger.java new file mode 100644 index 000000000..6c81a6c6e --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/onap/appc/test/InterceptLogger.java @@ -0,0 +1,449 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + + +package org.onap.appc.test; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import org.slf4j.Marker; +import ch.qos.logback.classic.Level; + +/** + * This class is used as an intercept logger that can be used in testing to intercept and record all + * messages that are logged, thus allowing a junit test case to examine the log output and make + * assertions. + */ +public class InterceptLogger implements org.slf4j.Logger { + + /** + * This inner class represents an intercepted log event. + */ + public class LogRecord { + private Level level; + private String message; + private long timestamp; + private Throwable t; + + public LogRecord(Level level, String message) { + setLevel(level); + setTimestamp(System.currentTimeMillis()); + setMessage(message); + } + + public LogRecord(Level level, String message, Throwable t) { + this(level, message); + setThrowable(t); + } + + /** + * @return the value of level + */ + public Level getLevel() { + return level; + } + + /** + * @return the value of message + */ + public String getMessage() { + return message; + } + + /** + * @return the value of timestamp + */ + public long getTimestamp() { + return timestamp; + } + + /** + * @param level the value for level + */ + public void setLevel(Level level) { + this.level = level; + } + + /** + * @param message the value for message + */ + public void setMessage(String message) { + this.message = message; + } + + /** + * @param timestamp the value for timestamp + */ + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + /** + * @return the value of t + */ + public Throwable getThrowable() { + return t; + } + + /** + * @param t the value for t + */ + public void setThrowable(Throwable t) { + this.t = t; + } + + } + + /** + * The list of all intercepted log events + */ + private List events; + + /** + * Create the intercept logger + */ + public InterceptLogger() { + events = new ArrayList(1000); + } + + /** + * @return Returns all intercepted log events + */ + public List getLogRecords() { + return events; + } + + /** + * Clears all log events + */ + public void clear() { + events.clear(); + } + + @Override + public void debug(Marker marker, String msg) { + debug(msg); + } + + @Override + public void debug(Marker marker, String format, Object arg) { + debug(MessageFormat.format(format, arg)); + } + + @Override + public void debug(Marker marker, String format, Object... arguments) { + debug(MessageFormat.format(format, arguments)); + } + + @Override + public void debug(Marker marker, String format, Object arg1, Object arg2) { + debug(MessageFormat.format(format, arg1, arg2)); + } + + @Override + public void debug(Marker marker, String msg, Throwable t) { + debug(msg, t); + } + + @Override + public void debug(String msg) { + events.add(new LogRecord(Level.DEBUG, msg)); + } + + @Override + public void debug(String format, Object arg) { + events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arg))); + } + + @Override + public void debug(String format, Object... arguments) { + events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arguments))); + } + + @Override + public void debug(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void debug(String msg, Throwable t) { + events.add(new LogRecord(Level.DEBUG, msg, t)); + } + + @Override + public void error(Marker marker, String msg) { + error(msg); + } + + @Override + public void error(Marker marker, String format, Object arg) { + error(format, arg); + } + + @Override + public void error(Marker marker, String format, Object... arguments) { + error(format, arguments); + } + + @Override + public void error(Marker marker, String format, Object arg1, Object arg2) { + error(format, arg1, arg2); + } + + @Override + public void error(Marker marker, String msg, Throwable t) { + events.add(new LogRecord(Level.ERROR, msg, t)); + } + + @Override + public void error(String msg) { + events.add(new LogRecord(Level.ERROR, msg)); + } + + @Override + public void error(String format, Object arg) { + events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arg))); + } + + @Override + public void error(String format, Object... arguments) { + events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arguments))); + } + + @Override + public void error(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void error(String msg, Throwable t) { + events.add(new LogRecord(Level.ERROR, msg, t)); + } + + @Override + public String getName() { + return null; + } + + @Override + public void info(Marker marker, String msg) { + info(msg); + } + + @Override + public void info(Marker marker, String format, Object arg) { + info(format, arg); + } + + @Override + public void info(Marker marker, String format, Object... arguments) { + info(format, arguments); + } + + @Override + public void info(Marker marker, String format, Object arg1, Object arg2) { + info(format, arg1, arg2); + } + + @Override + public void info(Marker marker, String msg, Throwable t) { + events.add(new LogRecord(Level.INFO, msg, t)); + } + + @Override + public void info(String msg) { + events.add(new LogRecord(Level.INFO, msg)); + } + + @Override + public void info(String format, Object arg) { + events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arg))); + } + + @Override + public void info(String format, Object... arguments) { + events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arguments))); + } + + @Override + public void info(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void info(String msg, Throwable t) { + events.add(new LogRecord(Level.INFO, msg, t)); + } + + @Override + public boolean isDebugEnabled() { + return true; + } + + @Override + public boolean isDebugEnabled(Marker marker) { + return true; + } + + @Override + public boolean isErrorEnabled() { + return true; + } + + @Override + public boolean isErrorEnabled(Marker marker) { + return true; + } + + @Override + public boolean isInfoEnabled() { + return true; + } + + @Override + public boolean isInfoEnabled(Marker marker) { + return true; + } + + @Override + public boolean isTraceEnabled() { + return true; + } + + @Override + public boolean isTraceEnabled(Marker marker) { + return true; + } + + @Override + public boolean isWarnEnabled() { + return true; + } + + @Override + public boolean isWarnEnabled(Marker marker) { + return true; + } + + @Override + public void trace(Marker marker, String msg) { + trace(msg); + } + + @Override + public void trace(Marker marker, String format, Object arg) { + trace(format, arg); + } + + @Override + public void trace(Marker marker, String format, Object... argArray) { + trace(format, argArray); + } + + @Override + public void trace(Marker marker, String format, Object arg1, Object arg2) { + trace(format, arg1, arg2); + } + + @Override + public void trace(Marker marker, String msg, Throwable t) { + trace(msg, t); + } + + @Override + public void trace(String msg) { + events.add(new LogRecord(Level.TRACE, msg)); + } + + @Override + public void trace(String format, Object arg) { + events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arg))); + } + + @Override + public void trace(String format, Object... arguments) { + events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arguments))); + } + + @Override + public void trace(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void trace(String msg, Throwable t) { + events.add(new LogRecord(Level.TRACE, msg, t)); + } + + @Override + public void warn(Marker marker, String msg) { + warn(msg); + } + + @Override + public void warn(Marker marker, String format, Object arg) { + warn(format, arg); + } + + @Override + public void warn(Marker marker, String format, Object... arguments) { + warn(format, arguments); + } + + @Override + public void warn(Marker marker, String format, Object arg1, Object arg2) { + warn(format, arg1, arg2); + } + + @Override + public void warn(Marker marker, String msg, Throwable t) { + events.add(new LogRecord(Level.WARN, msg, t)); + } + + @Override + public void warn(String msg) { + events.add(new LogRecord(Level.WARN, msg)); + } + + @Override + public void warn(String format, Object arg) { + events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arg))); + } + + @Override + public void warn(String format, Object... arguments) { + events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arguments))); + } + + @Override + public void warn(String format, Object arg1, Object arg2) { + events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arg1, arg2))); + } + + @Override + public void warn(String msg, Throwable t) { + events.add(new LogRecord(Level.WARN, msg, t)); + } +} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestIdentityUrl.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestIdentityUrl.java deleted file mode 100644 index dac22eadb..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestIdentityUrl.java +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - -package org.onap.appc.adapter.iaas.impl; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import java.util.Properties; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.appc.adapter.iaas.impl.IdentityURL; -import org.onap.appc.configuration.ConfigurationFactory; - -public class TestIdentityUrl { - - private static String URL; - - @BeforeClass - public static void before() { - Properties props = ConfigurationFactory.getConfiguration().getProperties(); - URL = props.getProperty(""); - } - - /** - * Test that we can parse and interpret valid URLs - */ - @Test - public void testValidURL1() { - URL = "http://192.168.1.1:5000/v2.0/"; - IdentityURL idurl = IdentityURL.parseURL(URL); - assertNotNull(idurl); - assertTrue(idurl.getScheme().equals("http")); - assertTrue(idurl.getHost().equals("192.168.1.1")); - assertTrue(idurl.getPort().equals("5000")); - assertNull(idurl.getPath()); - assertTrue(idurl.getVersion().equals("v2.0")); - assertTrue(idurl.toString().equals("http://192.168.1.1:5000/v2.0")); - } - - @Test - public void testValidURL2() { - URL = "https://192.168.1.1:5000/v3/"; - IdentityURL idurl = IdentityURL.parseURL(URL); - assertNotNull(idurl); - assertTrue(idurl.getScheme().equals("https")); - assertTrue(idurl.getHost().equals("192.168.1.1")); - assertTrue(idurl.getPort().equals("5000")); - assertNull(idurl.getPath()); - assertTrue(idurl.getVersion().equals("v3")); - assertTrue(idurl.toString().equals("https://192.168.1.1:5000/v3")); - } - - @Test - public void testValidURL3() { - URL = "http://192.168.1.1/v2.0/"; - IdentityURL idurl = IdentityURL.parseURL(URL); - assertNotNull(idurl); - assertTrue(idurl.getScheme().equals("http")); - assertTrue(idurl.getHost().equals("192.168.1.1")); - assertNull(idurl.getPort()); - assertNull(idurl.getPath()); - assertTrue(idurl.getVersion().equals("v2.0")); - System.out.println(idurl.toString()); - assertTrue(idurl.toString().equals("http://192.168.1.1/v2.0")); - } - - @Test - public void testValidURL4() { - URL = "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3"; - IdentityURL idurl = IdentityURL.parseURL(URL); - assertNotNull(idurl); - assertTrue(idurl.getScheme().equals("http")); - assertTrue(idurl.getHost().equals("msb.onap.org")); - assertTrue(idurl.getPort().equals("80")); - assertTrue(idurl.getPath().equals("/api/multicloud/v0/cloudowner_region/identity")); - assertTrue(idurl.getVersion().equals("v3")); - assertTrue(idurl.toString().equals("http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/identity/v3")); - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestProviderAdapterImpl.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestProviderAdapterImpl.java deleted file mode 100644 index 386c1115b..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestProviderAdapterImpl.java +++ /dev/null @@ -1,901 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.iaas.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.onap.appc.Constants; -import org.onap.appc.adapter.iaas.ProviderAdapter; -import org.onap.appc.adapter.iaas.impl.ProviderAdapterImpl; -import org.onap.appc.adapter.iaas.impl.ProviderCache; -import org.onap.appc.adapter.iaas.impl.ServiceCatalog; -import org.onap.appc.adapter.iaas.impl.TenantCache; -import org.onap.appc.adapter.iaas.impl.VMURL; -import org.onap.appc.configuration.ConfigurationFactory; -import org.onap.appc.exceptions.APPCException; -import org.onap.appc.exceptions.UnknownProviderException; -import com.att.cdp.exceptions.ZoneException; -import com.att.cdp.zones.ComputeService; -import com.att.cdp.zones.Context; -import com.att.cdp.zones.ContextFactory; -import com.att.cdp.zones.model.Image; -import com.att.cdp.zones.model.Server; -import com.att.cdp.zones.model.Server.Status; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.woorea.openstack.keystone.model.Access.Service.Endpoint; - -/** - * Test the ProviderAdapter implementation. - */ -@Category(org.onap.appc.adapter.iaas.impl.TestProviderAdapterImpl.class) -public class TestProviderAdapterImpl { - - @SuppressWarnings("nls") - private static final String PROVIDER_NAME = "ILAB"; - - @SuppressWarnings("nls") - private static final String PROVIDER_TYPE = "OpenStackProvider"; - - private static String IDENTITY_URL; - - private static String PRINCIPAL; - - private static String CREDENTIAL; - - private static String TENANT_NAME; - - private static String TENANT_ID; - - private static String USER_ID; - - private static String REGION_NAME; - - private static String SERVER_URL; - - private static Class providerAdapterImplClass; - private static Class configurationFactoryClass; - private static Field providerCacheField; - private static Field configField; - - private ProviderAdapterImpl adapter; - - /** - * Use reflection to locate fields and methods so that they can be manipulated during the test - * to change the internal state accordingly. - * - * @throws NoSuchFieldException if the field(s) dont exist - * @throws SecurityException if reflective access is not allowed - * @throws NoSuchMethodException If the method(s) dont exist - */ - @SuppressWarnings("nls") - @BeforeClass - public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException { - providerAdapterImplClass = ProviderAdapterImpl.class; - configurationFactoryClass = ConfigurationFactory.class; - - providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache"); - providerCacheField.setAccessible(true); - - configField = configurationFactoryClass.getDeclaredField("config"); - configField.setAccessible(true); - - Properties props = ConfigurationFactory.getConfiguration().getProperties(); - IDENTITY_URL = props.getProperty("provider1.identity"); - PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc"); - CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc"); - TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc"); - TENANT_ID = props.getProperty("provider1.tenant1.id", "abcde12345fghijk6789lmnopq123rst"); - REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne"); - SERVER_URL = props.getProperty("test.url"); - } - - /** - * Setup the test environment. - * - * @throws IllegalAccessException if this Field object is enforcing Java language access control - * and the underlying field is either inaccessible or final. - * @throws IllegalArgumentException if the specified object is not an instance of the class or - * interface declaring the underlying field (or a subclass or implementor thereof), or - * if an unwrapping conversion fails. - * @throws NullPointerException if the specified object is null and the field is an instance - * field. - * @throws ExceptionInInitializerError if the initialization provoked by this method fails. - */ - @Before - public void setup() throws IllegalArgumentException, IllegalAccessException { - configField.set(null, null); - Properties properties = new Properties(); - adapter = new ProviderAdapterImpl(properties); - } - - /** - * This method inspects the provider adapter implementation to make sure that the cache of - * providers and tenants, as well as the service catalog, and all pools of contexts have been - * set up correctly. - * - * @throws IllegalAccessException if this Field object is enforcing Java language access control - * and the underlying field is inaccessible. - * @throws IllegalArgumentException if the specified object is not an instance of the class or - * interface declaring the underlying field (or a subclass or implementor thereof). - */ - @SuppressWarnings({"unchecked"}) - @Ignore - @Test - public void validateCacheIsCreatedCorrectly() throws IllegalArgumentException, IllegalAccessException { - Map providerCaches = (Map) providerCacheField.get(adapter); - - assertNotNull(providerCaches); - assertEquals(1, providerCaches.size()); - assertTrue(providerCaches.containsKey(PROVIDER_NAME)); - - ProviderCache providerCache = providerCaches.get(PROVIDER_NAME); - assertEquals(PROVIDER_NAME, providerCache.getProviderName()); - assertEquals(PROVIDER_TYPE, providerCache.getProviderType()); - - Map tenantCaches = providerCache.getTenants(); - assertNotNull(tenantCaches); - assertEquals(1, tenantCaches.size()); - assertTrue(tenantCaches.containsKey(TENANT_NAME)); - - TenantCache tenantCache = tenantCaches.get(TENANT_NAME); - - assertEquals(TENANT_ID, tenantCache.getTenantId()); - assertEquals(TENANT_NAME, tenantCache.getTenantName()); - assertEquals(USER_ID, tenantCache.getUserid()); - - ServiceCatalog catalog = tenantCache.getServiceCatalog(); - assertNotNull(catalog); - - System.out.println(catalog.toString()); - List serviceTypes = catalog.getServiceTypes(); - assertNotNull(serviceTypes); - assertEquals(12, serviceTypes.size()); - - assertEquals(TENANT_NAME, catalog.getProjectName()); - assertEquals(TENANT_ID, catalog.getProjectId()); - - Set regionNames = catalog.getRegions(); - assertNotNull(regionNames); - assertEquals(1, regionNames.size()); - assertTrue(regionNames.contains(REGION_NAME)); - - List endpoints = catalog.getEndpoints(ServiceCatalog.IDENTITY_SERVICE); - assertNotNull(endpoints); - assertEquals(1, endpoints.size()); - Endpoint endpoint = (Endpoint) endpoints.get(0); - assertNotNull(endpoint); - assertEquals(REGION_NAME, endpoint.getRegion()); - assertEquals(IDENTITY_URL, endpoint.getPublicURL()); - - endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE); - assertNotNull(endpoints); - assertEquals(1, endpoints.size()); - endpoint = (Endpoint) endpoints.get(0); - assertNotNull(endpoint); - assertEquals(REGION_NAME, endpoint.getRegion()); - - endpoints = catalog.getEndpoints(ServiceCatalog.VOLUME_SERVICE); - assertNotNull(endpoints); - assertEquals(1, endpoints.size()); - endpoint = (Endpoint) endpoints.get(0); - assertNotNull(endpoint); - assertEquals(REGION_NAME, endpoint.getRegion()); - - endpoints = catalog.getEndpoints(ServiceCatalog.IMAGE_SERVICE); - assertNotNull(endpoints); - assertEquals(1, endpoints.size()); - endpoint = (Endpoint) endpoints.get(0); - assertNotNull(endpoint); - assertEquals(REGION_NAME, endpoint.getRegion()); - - endpoints = catalog.getEndpoints(ServiceCatalog.NETWORK_SERVICE); - assertNotNull(endpoints); - assertEquals(1, endpoints.size()); - endpoint = (Endpoint) endpoints.get(0); - assertNotNull(endpoint); - assertEquals(REGION_NAME, endpoint.getRegion()); - - assertTrue(catalog.isServicePublished(ServiceCatalog.IDENTITY_SERVICE)); - assertTrue(catalog.isServicePublished(ServiceCatalog.COMPUTE_SERVICE)); - assertTrue(catalog.isServicePublished(ServiceCatalog.VOLUME_SERVICE)); - assertTrue(catalog.isServicePublished(ServiceCatalog.IMAGE_SERVICE)); - assertTrue(catalog.isServicePublished(ServiceCatalog.NETWORK_SERVICE)); - } - - /** - * This test case is used to actually validate that a server has been restarted from an already - * running state - * - * @throws ZoneException If the login cannot be performed because the principal and/or - * credentials are invalid. - * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if - * the expected argument(s) are not defined or are invalid - * @throws IllegalStateException If the identity service is not available or cannot be created - * @throws IOException if an I/O error occurs - * @throws APPCException - */ - // @Ignore - @Test - public void testRestartRunningServer() - throws IllegalStateException, IllegalArgumentException, ZoneException, IOException, APPCException { - Properties properties = new Properties(); - properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); - properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); - properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); - properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - properties.setProperty(ContextFactory.PROPERTY_DISABLE_PROXY, "true"); - - try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { - context.login(PRINCIPAL, CREDENTIAL); - VMURL vm = VMURL.parseURL(SERVER_URL); - - ComputeService computeService = context.getComputeService(); - Server server = computeService.getServer(vm.getServerId()); - if (!server.getStatus().equals(Status.RUNNING)) { - server.start(); - assertTrue(waitForStateChange(server, Status.RUNNING)); - } - - Map params = new HashMap<>(); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); - params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); - SvcLogicContext svcContext = new SvcLogicContext(); - - server = adapter.restartServer(params, svcContext); - - assertEquals(Server.Status.RUNNING, server.getStatus()); - } - } - - - /****************************************/ - /** - * Tests that the vmStatuschecker method works and returns the correct status of the VM - * requested - * - * @throws ZoneException If the login cannot be performed because the principal and/or - * credentials are invalid. - * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if - * the expected argument(s) are not defined or are invalid - * @throws IllegalStateException If the identity service is not available or cannot be created - * @throws IOException if an I/O error occurs - * @throws UnknownProviderException If the provider cannot be found - */ - // @Ignore - @Test - public void testVmStatuschecker() throws IllegalStateException, IllegalArgumentException, ZoneException, - UnknownProviderException, IOException { - Properties properties = new Properties(); - properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); - properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); - properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); - properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - properties.setProperty(ContextFactory.PROPERTY_DISABLE_PROXY, "true"); - - try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { - context.login(PRINCIPAL, CREDENTIAL); - VMURL vm = VMURL.parseURL(SERVER_URL); - - ComputeService computeService = context.getComputeService(); - Server server = computeService.getServer(vm.getServerId()); - if (!server.getStatus().equals(Status.RUNNING)) { - server.start(); - assertTrue(waitForStateChange(server, Status.RUNNING)); - } - // or instead of the if-block, can ensureRunning(server) be used? - ensureRunning(server); - assertEquals(Server.Status.RUNNING, server.getStatus()); - } - } - - /****************************************/ - - - /** - * Tests that we can restart a server that is already stopped - * - * @throws ZoneException If the login cannot be performed because the principal and/or - * credentials are invalid. - * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if - * the expected argument(s) are not defined or are invalid. - * @throws IllegalStateException If the identity service is not available or cannot be created - * @throws IOException if an I/O error occurs - * @throws APPCException - */ - // @Ignore - @Test - public void testRestartStoppedServer() - throws IllegalStateException, IllegalArgumentException, ZoneException, IOException, APPCException { - Properties properties = new Properties(); - properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); - properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); - properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); - properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - - try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { - context.login(PRINCIPAL, CREDENTIAL); - VMURL vm = VMURL.parseURL(SERVER_URL); - - ComputeService computeService = context.getComputeService(); - Server server = computeService.getServer(vm.getServerId()); - if (!server.getStatus().equals(Status.READY)) { - server.stop(); - assertTrue(waitForStateChange(server, Status.READY)); - } - - Map params = new HashMap<>(); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); - params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); - SvcLogicContext svcContext = new SvcLogicContext(); - - server = adapter.restartServer(params, svcContext); - - assertEquals(Server.Status.RUNNING, server.getStatus()); - - } - } - - /** - * Tests that we can rebuild a running server (not created from a bootable volume) - * - * @throws ZoneException If the login cannot be performed because the principal and/or - * credentials are invalid. - * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if - * the expected argument(s) are not defined or are invalid. - * @throws IllegalStateException If the identity service is not available or cannot be created - * @throws UnknownProviderException If the provider cannot be found - * @throws IOException if an I/O error occurs - * @throws APPCException If the server cannot be rebuilt for some reason - */ - // @Ignore - @Test - public void testRebuildRunningServer() - throws IOException, IllegalStateException, IllegalArgumentException, ZoneException, APPCException { - Properties properties = new Properties(); - properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); - properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); - properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); - properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - - try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { - context.login(PRINCIPAL, CREDENTIAL); - VMURL vm = VMURL.parseURL(SERVER_URL); - - ComputeService computeService = context.getComputeService(); - Server server = computeService.getServer(vm.getServerId()); - ensureRunning(server); - - Map params = new HashMap<>(); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); - params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); - SvcLogicContext svcContext = new SvcLogicContext(); - - server = adapter.rebuildServer(params, svcContext); - assertTrue(waitForStateChange(server, Status.RUNNING)); - - } - } - - /** - * Tests that we can rebuild a paused server (not created from a bootable volume) - * - * @throws ZoneException If the login cannot be performed because the principal and/or - * credentials are invalid. - * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if - * the expected argument(s) are not defined or are invalid. - * @throws IllegalStateException If the identity service is not available or cannot be created - * @throws UnknownProviderException If the provider cannot be found - * @throws IOException if an I/O error occurs - * @throws APPCException If the server cannot be rebuilt for some reason - */ - // @Ignore - @Test - public void testRebuildPausedServer() - throws IOException, IllegalStateException, IllegalArgumentException, ZoneException, APPCException { - Properties properties = new Properties(); - properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); - properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); - properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); - properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - - try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { - context.login(PRINCIPAL, CREDENTIAL); - VMURL vm = VMURL.parseURL(SERVER_URL); - - ComputeService computeService = context.getComputeService(); - Server server = computeService.getServer(vm.getServerId()); - ensurePaused(server); - - Map params = new HashMap<>(); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); - params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); - SvcLogicContext svcContext = new SvcLogicContext(); - - server = adapter.rebuildServer(params, svcContext); - assertTrue(waitForStateChange(server, Status.RUNNING)); - } - } - - /** - * Tests that we can rebuild a paused server (not created from a bootable volume) - * - * @throws ZoneException If the login cannot be performed because the principal and/or - * credentials are invalid. - * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if - * the expected argument(s) are not defined or are invalid. - * @throws IllegalStateException If the identity service is not available or cannot be created - * @throws UnknownProviderException If the provider cannot be found - * @throws IOException if an I/O error occurs - * @throws APPCException If the server cannot be rebuilt for some reason - */ - // @Ignore - @Test - public void testRebuildSuspendedServer() - throws IOException, IllegalStateException, IllegalArgumentException, ZoneException, APPCException { - Properties properties = new Properties(); - properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); - properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); - properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); - properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - - try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { - context.login(PRINCIPAL, CREDENTIAL); - VMURL vm = VMURL.parseURL(SERVER_URL); - - ComputeService computeService = context.getComputeService(); - Server server = computeService.getServer(vm.getServerId()); - ensureSuspended(server); - - Map params = new HashMap<>(); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); - params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); - SvcLogicContext svcContext = new SvcLogicContext(); - - server = adapter.rebuildServer(params, svcContext); - assertTrue(waitForStateChange(server, Status.RUNNING)); - } - } - - /** - * Tests that we can rebuild a paused server (not created from a bootable volume) - * - * @throws ZoneException If the login cannot be performed because the principal and/or - * credentials are invalid. - * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if - * the expected argument(s) are not defined or are invalid. - * @throws IllegalStateException If the identity service is not available or cannot be created - * @throws UnknownProviderException If the provider cannot be found - * @throws IOException if an I/O error occurs - * @throws APPCException If the server cannot be rebuilt for some reason - */ - // @Ignore - @Test - public void testRebuildStoppedServer() - throws IOException, IllegalStateException, IllegalArgumentException, ZoneException, APPCException { - Properties properties = new Properties(); - properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, IDENTITY_URL); - properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); - properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); - properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - - try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { - context.login(PRINCIPAL, CREDENTIAL); - VMURL vm = VMURL.parseURL(SERVER_URL); - - ComputeService computeService = context.getComputeService(); - Server server = computeService.getServer(vm.getServerId()); - ensureStopped(server); - - Map params = new HashMap<>(); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); - params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); - SvcLogicContext svcContext = new SvcLogicContext(); - - server = adapter.rebuildServer(params, svcContext); - assertTrue(waitForStateChange(server, Status.RUNNING)); - } - } - - /** - * Test subsequent action on second vm in different Tenant resulting in {"itemNotFound": - * {"message": "Instance could not be found", "code": 404}} - * - * @throws ZoneException If the login cannot be performed because the principal and/or - * credentials are invalid. - * @throws IllegalArgumentException If the principal and/or credential are null or empty, or if - * the expected argument(s) are not defined or are invalid - * @throws IllegalStateException If the identity service is not available or cannot be created - * @throws IOException if an I/O error occurs - * @throws APPCException - */ - - @Test - public void testTenantVerification() - throws IllegalStateException, IllegalArgumentException, ZoneException, IOException, APPCException { - - Properties properties = new Properties(); - properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, "http://example.com:5000"); - properties.setProperty(ContextFactory.PROPERTY_TENANT, "APP-C"); - properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - - String vmUrl = - "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; - - // try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { - // context.login("AppC", "AppC"); - - // call lookupServer on vm in defined tenant "APP-C_TLV" - VMURL vm = VMURL.parseURL(vmUrl); - - Map params = new HashMap<>(); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, vmUrl); - params.put(ProviderAdapter.PROPERTY_IDENTITY_URL, "http://example.com:5000/v2.0"); - params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, "http://example.com:5000/v2.0"); - SvcLogicContext svcContext = new SvcLogicContext(); - - long start, end = 0; - - System.out.println("\n--------------------Begin lookupServer on tenant 1--------------------"); - start = System.currentTimeMillis(); - Server server = adapter.lookupServer(params, svcContext); - end = System.currentTimeMillis(); - - System.out.println(String.format("lookupServer on tenant 1 took %ds", (end - start) / 1000)); - System.out.println("----------------------------------------------------------------------\n"); - assertNotNull(server); - - // repeat to show that context is reused for second request - System.out.println("\n-----------------Begin repeat lookupServer on tenant 1----------------"); - start = System.currentTimeMillis(); - server = adapter.lookupServer(params, svcContext); - end = System.currentTimeMillis(); - - System.out.println(String.format("Repeat lookupServer on tenant 1 took %ds", (end - start) / 1000)); - System.out.println("----------------------------------------------------------------------\n"); - assertNotNull(server); - - // call lookupServer on vm in second tenant "Play" - // This is where we would fail due to using the previous - // tenants context - vmUrl = "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; - vm = VMURL.parseURL(vmUrl); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, vmUrl); - - System.out.println("\n--------------------Begin lookupServer on tenant 2--------------------"); - start = System.currentTimeMillis(); - server = adapter.lookupServer(params, svcContext); - end = System.currentTimeMillis(); - System.out.println(String.format("\nlookupServer on tenant 2 took %ds", (end - start) / 1000)); - System.out.println("----------------------------------------------------------------------\n"); - assertNotNull(server); - - // call lookupServer on vm in non-existing tenant - vmUrl = "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; - vm = VMURL.parseURL(vmUrl); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, vmUrl); - - System.out.println("\n--------------Begin lookupServer on non-existant tenant--------------"); - start = System.currentTimeMillis(); - server = adapter.lookupServer(params, svcContext); - end = System.currentTimeMillis(); - System.out.println(String.format("\nlookupServer on tenant 3 took %ds", (end - start) / 1000)); - System.out.println("----------------------------------------------------------------------\n"); - assertNull(server); - - // } - } - - /****************************************/ - - - @Test - public void testSnapshotServer() throws Exception { - Properties properties = new Properties(); - properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, "http://example.com:5000"); - // properties.setProperty(ContextFactory.PROPERTY_REGION, ""); - properties.setProperty(ContextFactory.PROPERTY_TENANT, "Play"); - properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - - String vmUrl = - "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; - - try (Context context = ContextFactory.getContext(PROVIDER_TYPE, properties)) { - context.login("AppC", "AppC"); - VMURL vm = VMURL.parseURL(vmUrl); - - Map params = new HashMap<>(); - params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, vmUrl); - params.put(ProviderAdapter.PROPERTY_IDENTITY_URL, "http://example.com:5000/v2.0"); - params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, "http://example.com:5000/v2.0"); - SvcLogicContext svcContext = new SvcLogicContext(); - - long start, end = 0; - - start = System.currentTimeMillis(); - Image image = adapter.createSnapshot(params, svcContext); - end = System.currentTimeMillis(); - - System.out.println(String.format("Image ID: %s", image.getId())); - System.out.println(String.format("Snapshot took %ds", (end - start) / 1000)); - - start = System.currentTimeMillis(); - adapter.rebuildServer(params, svcContext); - end = System.currentTimeMillis(); - System.out.println(String.format("Rebuild took %ds", (end - start) / 1000)); - } - - } - - /** - * Ensures that the server is in stopped (shutdown) state prior to test - * - * @param server The server to ensure is stopped - * @throws ZoneException If the server can't be operated upon for some reason - */ - @SuppressWarnings("nls") - private static void ensureStopped(Server server) throws ZoneException { - switch (server.getStatus()) { - case READY: - break; - - case PENDING: - waitForStateChange(server, Server.Status.READY, Server.Status.RUNNING, Server.Status.PAUSED, - Server.Status.SUSPENDED, Server.Status.ERROR); - ensureSuspended(server); - break; - - case PAUSED: - server.unpause(); - waitForStateChange(server, Server.Status.RUNNING); - server.stop(); - waitForStateChange(server, Server.Status.READY); - break; - - case SUSPENDED: - server.resume(); - waitForStateChange(server, Server.Status.RUNNING); - server.stop(); - waitForStateChange(server, Server.Status.READY); - break; - - case RUNNING: - server.stop(); - waitForStateChange(server, Server.Status.READY); - break; - - case DELETED: - case ERROR: - default: - fail("Server state is not valid for test - " + server.getStatus().name()); - } - } - - /** - * Ensures that the server is in suspended state prior to test - * - * @param server The server to ensure is suspended - * @throws ZoneException If the server can't be operated upon for some reason - */ - @SuppressWarnings("nls") - private static void ensureSuspended(Server server) throws ZoneException { - switch (server.getStatus()) { - case SUSPENDED: - break; - - case PENDING: - waitForStateChange(server, Server.Status.READY, Server.Status.RUNNING, Server.Status.PAUSED, - Server.Status.SUSPENDED, Server.Status.ERROR); - ensureSuspended(server); - break; - - case PAUSED: - server.unpause(); - waitForStateChange(server, Server.Status.RUNNING); - server.suspend(); - waitForStateChange(server, Server.Status.SUSPENDED); - break; - - case READY: - server.start(); - waitForStateChange(server, Server.Status.RUNNING); - server.suspend(); - waitForStateChange(server, Server.Status.SUSPENDED); - break; - - case RUNNING: - server.suspend(); - waitForStateChange(server, Server.Status.SUSPENDED); - break; - - case DELETED: - case ERROR: - default: - fail("Server state is not valid for test - " + server.getStatus().name()); - } - } - - /** - * This method makes sure that the indicated server is running before performing a test - * - * @param server The server to ensure is running - * @throws ZoneException If the server can't be operated upon - */ - @SuppressWarnings("nls") - private static void ensureRunning(Server server) throws ZoneException { - switch (server.getStatus()) { - case RUNNING: - break; - - case PENDING: - waitForStateChange(server, Server.Status.READY, Server.Status.RUNNING, Server.Status.PAUSED, - Server.Status.SUSPENDED, Server.Status.ERROR); - ensureRunning(server); - break; - - case PAUSED: - server.unpause(); - waitForStateChange(server, Server.Status.RUNNING); - break; - - case SUSPENDED: - server.resume(); - waitForStateChange(server, Server.Status.RUNNING); - break; - - case READY: - server.start(); - waitForStateChange(server, Server.Status.RUNNING); - break; - - case DELETED: - case ERROR: - default: - fail("Server state is not valid for test - " + server.getStatus().name()); - } - } - - /** - * This method will make sure that the server we are testing is paused - * - * @param server The server to make sure is paused for the test - * @throws ZoneException If anything fails - */ - @SuppressWarnings("nls") - private static void ensurePaused(Server server) throws ZoneException { - switch (server.getStatus()) { - case PAUSED: - break; - - case PENDING: - waitForStateChange(server, Server.Status.READY, Server.Status.RUNNING, Server.Status.PAUSED, - Server.Status.SUSPENDED, Server.Status.ERROR); - ensurePaused(server); - break; - - case READY: - server.start(); - waitForStateChange(server, Server.Status.RUNNING); - server.pause(); - waitForStateChange(server, Server.Status.PAUSED); - break; - - case RUNNING: - server.pause(); - waitForStateChange(server, Server.Status.PAUSED); - break; - - case SUSPENDED: - server.resume(); - waitForStateChange(server, Server.Status.RUNNING); - server.pause(); - waitForStateChange(server, Server.Status.PAUSED); - break; - - case ERROR: - case DELETED: - default: - fail("Server state is not valid for test - " + server.getStatus().name()); - } - } - - /** - * Enter a pool-wait loop checking the server state to see if it has entered one of the desired - * states or not. - *

- * This method checks the state of the server periodically for one of the desired states. When - * the server enters one of the desired states, the method returns a successful indication - * (true). If the server never enters one of the desired states within the alloted timeout - * period, then the method returns a failed response (false). No exceptions are thrown from this - * method. - *

- * - * @param server The server to wait on - * @param desiredStates A variable list of desired states, any one of which is allowed. - * @return True if the server entered one of the desired states, and false if not and the wait - * loop timed out. - */ - private static boolean waitForStateChange(Server server, Server.Status... desiredStates) { - int timeout = ConfigurationFactory.getConfiguration() - .getIntegerProperty(Constants.PROPERTY_SERVER_STATE_CHANGE_TIMEOUT); - long limit = System.currentTimeMillis() + (timeout * 1000); - Server vm = server; - - try { - while (limit > System.currentTimeMillis()) { - vm.refresh(); - for (Server.Status desiredState : desiredStates) { - if (server.getStatus().equals(desiredState)) { - return true; - } - } - - try { - Thread.sleep(10000L); - } catch (InterruptedException e) { - // ignore - } - } - } catch (ZoneException e) { - e.printStackTrace(); - } - - return false; - } - - /* - * @Test public void testTerminateStack() throws IllegalStateException, - * IllegalArgumentException, ZoneException, UnknownProviderException, IOException { Properties - * properties = new Properties(); properties.setProperty(ContextFactory.PROPERTY_IDENTITY_URL, - * IDENTITY_URL); properties.setProperty(ContextFactory.PROPERTY_REGION, REGION_NAME); - * properties.setProperty(ContextFactory.PROPERTY_TENANT, TENANT_NAME); - * properties.setProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "*"); - * properties.setProperty(ContextFactory.PROPERTY_DISABLE_PROXY, "true"); try (Context context = - * ContextFactory.getContext(PROVIDER_TYPE, properties)) { context.login(PRINCIPAL, CREDENTIAL); - * VMURL vm = VMURL.parseURL(SERVER_URL); ComputeService computeService = - * context.getComputeService(); Server server = computeService.getServer(vm.getServerId()); if - * (!server.getStatus().equals(Status.RUNNING)) { server.start(); - * assertTrue(waitForStateChange(server, Status.RUNNING)); } Map params = new - * HashMap<>(); params.put(ProviderAdapter.PROPERTY_INSTANCE_URL, SERVER_URL); - * params.put(ProviderAdapter.PROPERTY_PROVIDER_NAME, PROVIDER_NAME); SvcLogicContext svcContext - * = new SvcLogicContext(); Stack stack = adapter.terminateStack(params, svcContext); - * assertNotNull(stack); } } - */ - -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestProviderOperation.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestProviderOperation.java deleted file mode 100644 index c080cf953..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestProviderOperation.java +++ /dev/null @@ -1,162 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.iaas.impl; - -import java.lang.reflect.Field; -import java.util.Map; -import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation; -import org.onap.appc.exceptions.APPCException; -import com.att.cdp.zones.model.ModelObject; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.MDC; -import org.onap.appc.configuration.ConfigurationFactory; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import static org.onap.appc.adapter.iaas.provider.operation.common.constants.Constants.MDC_SERVICE; - -/** - * This class is used to test methods and functions of the adapter implementation that do not - * require and do not set up connections to any providers. - * - * @since Jan 20, 2016 - * @version $Id$ - */ - -public class TestProviderOperation extends ProviderOperation { - - private static Class providerAdapterImplClass; - private static Class configurationFactoryClass; - private static Field providerCacheField; - private static Field configField; - - /** - * Use reflection to locate fields and methods so that they can be manipulated during the test - * to change the internal state accordingly. - * - * @throws NoSuchFieldException if the field(s) dont exist - * @throws SecurityException if reflective access is not allowed - * @throws NoSuchMethodException If the method(s) dont exist - */ - @SuppressWarnings("nls") - @BeforeClass - public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException { - providerAdapterImplClass = ProviderAdapterImpl.class; - configurationFactoryClass = ConfigurationFactory.class; - - providerCacheField = providerAdapterImplClass.getDeclaredField("providerCache"); - providerCacheField.setAccessible(true); - - configField = configurationFactoryClass.getDeclaredField("config"); - configField.setAccessible(true); - } - - /** - * This test expects a failure because the value to be validated is a null URL - * - * @throws RequestFailedException Expected - */ - @SuppressWarnings("nls") - @Test(expected = RequestFailedException.class) - public void testValidateParameterPatternExpectFailNullValue() throws RequestFailedException { - MDC.put(MDC_SERVICE, "junit"); - SvcLogicContext svcContext = new SvcLogicContext(); - RequestContext rc = new RequestContext(svcContext); - String link = null; - - validateVMURL(VMURL.parseURL(link)); - } - - /** - * This test expects a failure because the value to be validated is an empty URL - * - * @throws RequestFailedException Expected - */ - @SuppressWarnings("nls") - @Test(expected = RequestFailedException.class) - public void testValidateParameterPatternExpectFailEmptyValue() throws RequestFailedException { - MDC.put(MDC_SERVICE, "junit"); - SvcLogicContext svcContext = new SvcLogicContext(); - RequestContext rc = new RequestContext(svcContext); - String link = ""; - - validateVMURL(VMURL.parseURL(link)); - } - - /** - * This test expects a failure because the value to be validated is a blank URL - * - * @throws RequestFailedException Expected - */ - @SuppressWarnings("nls") - @Test(expected = RequestFailedException.class) - public void testValidateParameterPatternExpectFailBlankValue() throws RequestFailedException { - MDC.put(MDC_SERVICE, "junit"); - SvcLogicContext svcContext = new SvcLogicContext(); - RequestContext rc = new RequestContext(svcContext); - String link = " "; - - validateVMURL(VMURL.parseURL(link)); - } - - /** - * This test expects a failure because the value to be validated is a bad URL - * - * @throws RequestFailedException Expected - */ - @SuppressWarnings("nls") - @Test(expected = RequestFailedException.class) - public void testValidateParameterPatternExpectFailBadURL() throws RequestFailedException { - MDC.put(MDC_SERVICE, "junit"); - SvcLogicContext svcContext = new SvcLogicContext(); - RequestContext rc = new RequestContext(svcContext); - String link = "http://some.host:1234/01d82c08594a4b23a0f9260c94be0c4d/"; - - validateVMURL(VMURL.parseURL(link)); - } - - /** - * This test expects to pass - * - * @throws RequestFailedException Un-Expected - */ - @SuppressWarnings("nls") - @Test - public void testValidateParameterPatternValidURL() throws RequestFailedException { - MDC.put(MDC_SERVICE, "junit"); - SvcLogicContext svcContext = new SvcLogicContext(); - RequestContext rc = new RequestContext(svcContext); - String link = - "http://some.host:1234/v2/01d82c08594a4b23a0f9260c94be0c4d/servers/f888f89f-096b-421e-ba36-34f714071551"; - - validateVMURL(VMURL.parseURL(link)); - } - - @Override - protected ModelObject executeProviderOperation(Map params, SvcLogicContext context) - throws APPCException { - return null; - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestRequestContext.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestRequestContext.java deleted file mode 100644 index 7ea30635c..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestRequestContext.java +++ /dev/null @@ -1,162 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - -package org.onap.appc.adapter.iaas.impl; - -import static org.junit.Assert.*; -import org.junit.Before; -import org.junit.Test; -import org.onap.appc.Constants; -import org.onap.appc.adapter.iaas.impl.RequestContext; -import org.onap.appc.configuration.Configuration; -import org.onap.appc.configuration.ConfigurationFactory; - -/** - * Test the RequestContext object - *

- * The request context is used to track retries, recovery attempts, and time to live of the - * processing of a request. - *

- */ - -public class TestRequestContext { - - private RequestContext rc; - private Configuration config = ConfigurationFactory.getConfiguration(); - - /** - * Set up the test environment by forcing the retry delay and limit to small values for the test - * and setting up the request context object. - */ - @Before - public void setup() { - config.setProperty(Constants.PROPERTY_RETRY_DELAY, "1"); - config.setProperty(Constants.PROPERTY_RETRY_LIMIT, "3"); - rc = new RequestContext(null); - rc.setTimeToLiveSeconds(2); - } - - /** - * Ensure that we set up the property correctly - */ - @Test - public void testRetryDelayProperty() { - assertEquals(1, rc.getRetryDelay()); - } - - /** - * Ensure that we set up the property correctly - */ - @Test - public void testRetryLimitProperty() { - assertEquals(3, rc.getRetryLimit()); - } - - /** - * This test ensures that the retry attempt counter is zero on a new context - */ - @Test - public void testRetryCountNoRetries() { - assertEquals(0, rc.getAttempts()); - } - - /** - * Test that the delay is accurate - */ - @Test - public void testDelay() { - long future = System.currentTimeMillis() + (rc.getRetryDelay() * 1000L); - - rc.delay(); - - assertTrue(System.currentTimeMillis() >= future); - } - - /** - * The RequestContext tracks the number of retry attempts against the limit. This test verifies - * that tracking logic works correctly. - */ - @Test - public void testCanRetry() { - assertEquals(0, rc.getAttempts()); - assertTrue(rc.attempt()); - assertEquals(1, rc.getAttempts()); - assertTrue(rc.attempt()); - assertEquals(2, rc.getAttempts()); - assertTrue(rc.attempt()); - assertEquals(3, rc.getAttempts()); - assertFalse(rc.attempt()); - assertEquals(3, rc.getAttempts()); - assertFalse(rc.attempt()); - assertEquals(3, rc.getAttempts()); - assertFalse(rc.attempt()); - assertEquals(3, rc.getAttempts()); - } - - /** - * The same RequestContext is used throughout the processing, and retries need to be reset once - * successfully connected so that any earlier (successful) recoveries are not considered when - * performing any new future recoveries. This test ensures that a reset clears the retry counter - * and that we can attempt retries again up to the limit. - */ - @Test - public void testResetAndCanRetry() { - assertTrue(rc.attempt()); - assertTrue(rc.attempt()); - assertTrue(rc.attempt()); - rc.reset(); - - assertTrue(rc.attempt()); - assertTrue(rc.attempt()); - assertTrue(rc.attempt()); - assertFalse(rc.attempt()); - assertFalse(rc.attempt()); - assertFalse(rc.attempt()); - } - - /** - * This test is used to test tracking of time to live for the request context. Because time is - * inexact, the assertions can only be ranges of values, such as at least some value or greater. - * The total duration tracking in the request context is only updated on each call to - * {@link RequestContext#isAlive()}. Also, durations are NOT affected by calls to reset. - */ - @Test - public void testTimeToLive() { - assertTrue(rc.getTotalDuration() == 0L); - assertTrue(rc.isAlive()); - rc.reset(); - rc.delay(); - assertTrue(rc.isAlive()); - assertTrue(rc.getTotalDuration() >= 1000L); - rc.reset(); - rc.delay(); - rc.isAlive(); - assertTrue(rc.getTotalDuration() >= 2000L); - rc.reset(); - rc.delay(); - assertFalse(rc.isAlive()); - assertTrue(rc.getTotalDuration() >= 3000L); - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalog.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalog.java deleted file mode 100644 index c1a41f209..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalog.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - - -package org.onap.appc.adapter.iaas.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import java.util.HashSet; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.appc.configuration.ConfigurationFactory; -import com.att.cdp.exceptions.ZoneException; -import com.woorea.openstack.keystone.model.Access.Service; - -/** - * This class tests the service catalog against a known provider. - */ -public class TestServiceCatalog { - - // Number - private static int EXPECTED_REGIONS = 2; - private static int EXPECTED_ENDPOINTS = 1; - - private static String PRINCIPAL; - private static String CREDENTIAL; - private static String TENANT_NAME; - private static String TENANT_ID; - private static String IDENTITY_URL; - private static String REGION_NAME; - - private ServiceCatalog catalog; - - private Properties properties; - - @BeforeClass - public static void before() { - Properties props = ConfigurationFactory.getConfiguration().getProperties(); - IDENTITY_URL = props.getProperty("provider1.identity"); - PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc"); - CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc"); - TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc"); - TENANT_ID = props.getProperty("provider1.tenant1.id", - props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst")); - REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne"); - - EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "2")); - EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0")); - } - - /** - * Setup the test environment by loading a new service catalog for each test - * - * @throws ZoneException - */ - @Before - public void setup() throws ZoneException { - properties = new Properties(); - catalog = Mockito.mock(ServiceCatalog.class, Mockito.CALLS_REAL_METHODS); - catalog.rwLock = new ReentrantReadWriteLock(); - - Set testdata = new HashSet<>(); - testdata.add("RegionOne"); - catalog.regions = testdata; - } - - /** - * Test that we find all of the expected region(s) - */ - @Test - public void testKnownRegions() { - assertEquals(EXPECTED_REGIONS, catalog.getRegions().size()); - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogFactory.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogFactory.java deleted file mode 100644 index e974d27ba..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogFactory.java +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.iaas.impl; - -import java.util.Properties; -import org.junit.Assert; -import org.junit.Test; - -public class TestServiceCatalogFactory { - - @Test - public void testGetServiceCatalogV2() { - String tenantIdentifier = null; - String principal = null; - String credential = null; - String domain = null; - Properties properties = null; - - String url = "http://192.168.1.1:5000/v2.0/"; - ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, - domain, properties); - Assert.assertNotNull(catalog); - Assert.assertEquals(catalog.getClass(), ServiceCatalogV2.class); - - url = "http://192.168.1.1:5000/v2/"; - catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, domain, - properties); - Assert.assertNotNull(catalog); - Assert.assertEquals(catalog.getClass(), ServiceCatalogV2.class); - - url = "http://192.168.1.1:5000/v2.1/"; - catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, domain, - properties); - Assert.assertNotNull(catalog); - Assert.assertEquals(catalog.getClass(), ServiceCatalogV2.class); - - } - - @Test - public void testGetServiceCatalogV3() { - String url = "http://192.168.1.1:5000/v3.0/"; - String tenantIdentifier = null; - String principal = null; - String credential = null; - String domain = null; - Properties properties = null; - ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, - domain, properties); - - Assert.assertNotNull(catalog); - Assert.assertEquals(catalog.getClass(), ServiceCatalogV3.class); - } - - @Test - public void testGetServiceCatalogOther() { - String url = "http://192.168.1.1:5000/v4.0/"; - String tenantIdentifier = null; - String principal = null; - String credential = null; - String domain = null; - Properties properties = null; - ServiceCatalog catalog = ServiceCatalogFactory.getServiceCatalog(url, tenantIdentifier, principal, credential, - domain, properties); - - Assert.assertNull(catalog); - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogV2.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogV2.java deleted file mode 100644 index 58b56e06f..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogV2.java +++ /dev/null @@ -1,174 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.adapter.iaas.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import com.att.cdp.exceptions.ZoneException; -import com.woorea.openstack.keystone.model.Access.Service; -import java.util.List; -import java.util.Properties; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.appc.configuration.ConfigurationFactory; - -/** - * This class tests the service catalog against a known provider. - */ -@Ignore -public class TestServiceCatalogV2 { - - // Number - private static int EXPECTED_REGIONS = 1; - private static int EXPECTED_ENDPOINTS = 1; - - private static String PRINCIPAL; - private static String CREDENTIAL; - private static String TENANT_NAME; - private static String TENANT_ID; - private static String IDENTITY_URL; - private static String REGION_NAME; - - private ServiceCatalogV2 catalog; - - private Properties properties; - - @BeforeClass - public static void before() { - Properties props = ConfigurationFactory.getConfiguration().getProperties(); - IDENTITY_URL = props.getProperty("provider1.identity", "appc"); - PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc"); - CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc"); - TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc"); - TENANT_ID = props.getProperty("provider1.tenant1.id", - props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst")); - REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne"); - - EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0")); - EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0")); - } - - /** - * Setup the test environment by loading a new service catalog for each test - * - * @throws ZoneException - */ - @Before - public void setup() throws ZoneException { - properties = new Properties(); - catalog = new ServiceCatalogV2(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, properties); - catalog.init(); - } - - /** - * Test that the tenant name and ID are returned correctly - */ - @Test - public void testKnownTenant() { - assertEquals(TENANT_NAME, catalog.getProjectName()); - assertEquals(TENANT_ID, catalog.getProjectId()); - } - - /** - * Test that we find all of the expected region(s) - */ - @Test - public void testKnownRegions() { - assertEquals(EXPECTED_REGIONS, catalog.getRegions().size()); - // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]); - } - - /** - * Test that we can check for published services correctly - */ - @Test - public void testServiceTypesPublished() { - assertTrue(catalog.isServicePublished("compute")); - assertFalse(catalog.isServicePublished("bogus")); - } - - /** - * Check that we can get the list of published services - */ - @Test - public void testPublishedServicesList() { - // List services = catalog.getServiceTypes(); - - // assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE)); - // assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE)); - // assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE)); - // assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE)); - // assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE)); - } - - /** - * Test that we can get the endpoint(s) for a service - */ - @Test - public void testEndpointList() { - List endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE); - - assertNotNull(endpoints); - assertFalse(endpoints.isEmpty()); - assertEquals(EXPECTED_ENDPOINTS, endpoints.size()); - - Service.Endpoint endpoint = endpoints.get(0); - // assertEquals(REGION_NAME, endpoint.getRegion()); - } - - @Test - public void testToString() { - String testString = catalog.toString(); - assertNotNull(testString); - } - - @Ignore - @Test - public void liveConnectionTest() { - // this test should only be used by developers when testing against a live Openstack - // instance, otherwise it should be ignored - properties = new Properties(); - String identity = "http://192.168.0.1:5000/v2.0"; - String tenantName = "Tenant"; - String user = "user"; - String pass = "pass"; - - ServiceCatalogV2 catalog = new ServiceCatalogV2(identity, tenantName, user, pass, properties); - - try { - catalog.init(); - } catch (ZoneException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - String out = catalog.toString(); - System.out.println(out); - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogV3.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogV3.java deleted file mode 100644 index 26a4d7dbf..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestServiceCatalogV3.java +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - - -package org.onap.appc.adapter.iaas.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import com.att.cdp.exceptions.ZoneException; -import com.woorea.openstack.keystone.v3.model.Token.Service.Endpoint; -import java.util.List; -import java.util.Properties; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.appc.configuration.ConfigurationFactory; - -/** - * This class tests the service catalog against a known provider. - */ -@Ignore -public class TestServiceCatalogV3 { - - // Number - private static int EXPECTED_REGIONS = 1; - private static int EXPECTED_ENDPOINTS = 1; - - private static String PRINCIPAL; - private static String CREDENTIAL; - private static String DOMAIN; - private static String TENANT_NAME; - private static String TENANT_ID; - private static String IDENTITY_URL; - private static String REGION_NAME; - - private ServiceCatalogV3 catalog; - - private Properties properties; - - @BeforeClass - public static void before() { - Properties props = ConfigurationFactory.getConfiguration().getProperties(); - IDENTITY_URL = props.getProperty("provider1.identity"); - PRINCIPAL = props.getProperty("provider1.tenant1.userid", "appc"); - CREDENTIAL = props.getProperty("provider1.tenant1.password", "appc"); - DOMAIN = props.getProperty("provider1.tenant1.domain", "Default"); - TENANT_NAME = props.getProperty("provider1.tenant1.name", "appc"); - TENANT_ID = props.getProperty("provider1.tenant1.id", - props.getProperty("test.tenantid", "abcde12345fghijk6789lmnopq123rst")); - REGION_NAME = props.getProperty("provider1.tenant1.region", "RegionOne"); - - EXPECTED_REGIONS = Integer.valueOf(props.getProperty("test.expected-regions", "0")); - EXPECTED_ENDPOINTS = Integer.valueOf(props.getProperty("test.expected-endpoints", "0")); - } - - /** - * Setup the test environment by loading a new service catalog for each test - * - * @throws ZoneException - */ - @Before - public void setup() throws ZoneException { - properties = new Properties(); - catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties); - } - - /** - * Test that the tenant name and ID are returned correctly - */ - @Test - public void testKnownTenant() { - assertEquals(TENANT_NAME, catalog.getProjectName()); - assertEquals(TENANT_ID, catalog.getProjectId()); - } - - /** - * Test that we find all of the expected region(s) - */ - @Test - public void testKnownRegions() { - assertEquals(EXPECTED_REGIONS, catalog.getRegions().size()); - // assertEquals(REGION_NAME, catalog.getRegions().toArray()[0]); - } - - /** - * Test that we can check for published services correctly - */ - @Test - public void testServiceTypesPublished() { - assertTrue(catalog.isServicePublished("compute")); - assertFalse(catalog.isServicePublished("bogus")); - } - - /** - * Check that we can get the list of published services - */ - @Test - public void testPublishedServicesList() { - List services = catalog.getServiceTypes(); - - assertTrue(services.contains(ServiceCatalog.COMPUTE_SERVICE)); - assertTrue(services.contains(ServiceCatalog.IDENTITY_SERVICE)); - assertTrue(services.contains(ServiceCatalog.IMAGE_SERVICE)); - assertTrue(services.contains(ServiceCatalog.NETWORK_SERVICE)); - assertTrue(services.contains(ServiceCatalog.VOLUME_SERVICE)); - } - - /** - * Test that we can get the endpoint(s) for a service - */ - @Test - public void testEndpointList() { - List endpoints = catalog.getEndpoints(ServiceCatalog.COMPUTE_SERVICE); - - assertNotNull(endpoints); - assertFalse(endpoints.isEmpty()); - assertEquals(EXPECTED_ENDPOINTS, endpoints.size()); - - Endpoint endpoint = endpoints.get(0); - // assertEquals(REGION_NAME, endpoint.getRegion()); - } - - @Test - public void testToString() { - String testString = catalog.toString(); - assertNotNull(testString); - } - - @Ignore - @Test - public void liveConnectionTest() { - // this test should only be used by developers when testing against a live Openstack - // instance, otherwise it should be ignored - properties = new Properties(); - String identity = ""; - String tenantName = ""; - String user = ""; - String pass = ""; - - catalog = new ServiceCatalogV3(IDENTITY_URL, TENANT_NAME, PRINCIPAL, CREDENTIAL, DOMAIN, properties); - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestVMURL.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestVMURL.java deleted file mode 100644 index d433afb64..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/adapter/iaas/impl/TestVMURL.java +++ /dev/null @@ -1,130 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - - -package org.onap.appc.adapter.iaas.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import java.util.Properties; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.appc.adapter.iaas.impl.VMURL; -import org.onap.appc.configuration.ConfigurationFactory; - -public class TestVMURL { - - private static String IP; - private static String PORT; - private static String TENANTID; - private static String VMID; - private static String URL; - - @BeforeClass - public static void before() { - Properties props = ConfigurationFactory.getConfiguration().getProperties(); - IP = props.getProperty("test.ip"); - PORT = props.getProperty("test.port"); - TENANTID = props.getProperty("test.tenantid"); - VMID = props.getProperty("test.vmid"); - } - - /** - * Test that we can parse and interpret valid URLs - */ - @Test - public void testValidURL1() { - URL = String.format("http://%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID); - VMURL url = VMURL.parseURL(URL); - - assertEquals("http", url.getScheme()); - assertEquals(IP, url.getHost()); - assertEquals(PORT, url.getPort()); - assertEquals(TENANTID, url.getTenantId()); - assertEquals(VMID, url.getServerId()); - assertEquals(url.toString(), URL); - } - - @Test - public void testValidURL2() { - URL = String.format("http://%s/v2/%s/servers/%s", IP, TENANTID, VMID); - VMURL url = VMURL.parseURL(URL); - assertEquals("http", url.getScheme()); - assertEquals(IP, url.getHost()); - assertNull(url.getPort()); - assertNull(url.getPath()); - assertEquals(TENANTID, url.getTenantId()); - assertEquals(VMID, url.getServerId()); - assertEquals(url.toString(), URL); - } - - @Test - public void testValidURL3() { - URL = "http://msb.onap.org:80/api/multicloud/v0/cloudowner_region/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345"; - VMURL url = VMURL.parseURL(URL); - assertNotNull(url); - assertEquals("http", url.getScheme()); - assertEquals("msb.onap.org", url.getHost()); - assertEquals("80", url.getPort()); - assertEquals("/api/multicloud/v0/cloudowner_region", url.getPath()); - assertEquals(TENANTID, url.getTenantId()); - assertEquals(VMID, url.getServerId()); - assertEquals(url.toString(), URL); - } - - /** - * Test that we ignore and return null for invalid URLs - */ - @Test - public void testInvalidURLs() { - VMURL url = VMURL.parseURL(null); - assertNull(url); - - url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID)); - assertNull(url); - - url = VMURL.parseURL(String.format("http:/%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID)); - assertNull(url); - - url = VMURL.parseURL(String.format("http:///%s:%s/v2/%s/servers/%s", IP, PORT, TENANTID, VMID)); - assertNull(url); - - url = VMURL.parseURL(String.format("http://v2/%s/servers/%s", TENANTID, VMID)); - assertNull(url); - - url = VMURL.parseURL(String.format("%s:%s/%s/servers/%s", IP, PORT, TENANTID, VMID)); - assertNull(url); - - url = VMURL.parseURL(String.format("%s:%s/v2/servers/%s", IP, PORT, VMID)); - assertNull(url); - - url = VMURL.parseURL(String.format("%s:%s/v2/%s/%s", IP, PORT, TENANTID, VMID)); - assertNull(url); - - url = VMURL.parseURL(String.format("%s:%s/v2/%s/servers", IP, PORT, TENANTID)); - assertNull(url); - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/test/ExecutorHarness.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/test/ExecutorHarness.java deleted file mode 100644 index 7a03a8d84..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/test/ExecutorHarness.java +++ /dev/null @@ -1,181 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - - -package org.onap.appc.test; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.onap.appc.test.InterceptLogger; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; - -/** - * This class is used as a test harness to wrap the call to an executor node. - */ - -public class ExecutorHarness { - - /** - * The executor to be tested - */ - private SvcLogicJavaPlugin executor; - - /** - * The collection of all exec methods found on the class - */ - private Map methods; - - /** - * The field of the class being tested that contains the reference to the logger to be used. - * This is modified to point to our interception logger for the test. - */ - private Field contextLogger; - - /** - * The interception logger that buffers all messages logged and allows us to look at them as - * part of the test case. - */ - private InterceptLogger logger; - - /** - * Create the harness and initialize it - * - * @throws SecurityException If a security manager, s, is present and any of the following - * conditions is met: - *
    - *
  • invocation of s.checkMemberAccess(this, Member.DECLARED) denies access to the - * declared field
  • - *
  • the caller's class loader is not the same as or an ancestor of the class loader - * for the current class and invocation of s.checkPackageAccess() denies access to the - * package of this class
  • - *
- * @throws NoSuchFieldException if a field with the specified name is not found. - * @throws IllegalAccessException if this Field object is enforcing Java language access control - * and the underlying field is either inaccessible or final. - * @throws IllegalArgumentException if the specified object is not an instance of the class or - * interface declaring the underlying field (or a subclass or implementor thereof), or - * if an unwrapping conversion fails. - */ - @SuppressWarnings("nls") - public ExecutorHarness() - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - methods = new HashMap<>(); - new SvcLogicContext(); - - Class contextClass = SvcLogicContext.class; - contextLogger = contextClass.getDeclaredField("LOG"); - contextLogger.setAccessible(true); - logger = new InterceptLogger(); - contextLogger.set(null, logger); - } - - /** - * Convenience constructor - * - * @param executor The executor to be tested by the harness - * @throws SecurityException If a security manager, s, is present and any of the following - * conditions is met: - *
    - *
  • invocation of s.checkMemberAccess(this, Member.DECLARED) denies access to the - * declared field
  • - *
  • the caller's class loader is not the same as or an ancestor of the class loader - * for the current class and invocation of s.checkPackageAccess() denies access to the - * package of this class
  • - *
- * @throws NoSuchFieldException if a field with the specified name is not found. - * @throws IllegalAccessException if this Field object is enforcing Java language access control - * and the underlying field is either inaccessible or final. - * @throws IllegalArgumentException if the specified object is not an instance of the class or - * interface declaring the underlying field (or a subclass or implementor thereof), or - * if an unwrapping conversion fails. - */ - public ExecutorHarness(SvcLogicJavaPlugin executor) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - this(); - setExecutor(executor); - } - - /** - * @param executor The java plugin class to be executed - */ - public void setExecutor(SvcLogicJavaPlugin executor) { - this.executor = executor; - scanExecutor(); - } - - /** - * @return The java plugin class to be executed - */ - public SvcLogicJavaPlugin getExecutor() { - return executor; - } - - /** - * @return The set of all methods that meet the signature requirements - */ - public List getExecMethodNames() { - List names = new ArrayList<>(); - names.addAll(methods.keySet()); - return names; - } - - /** - * Returns an indication if the named method is a valid executor method that could be called - * from a DG execute node - * - * @param methodName The method name to be validated - * @return True if the method name meets the signature requirements, false if the method either - * does not exist or does not meet the requirements. - */ - public boolean isExecMethod(String methodName) { - return methods.containsKey(methodName); - } - - /** - * This method scans the executor class hierarchy to locate all methods that match the required - * signature of the executor and records these methods in a map. - */ - private void scanExecutor() { - methods.clear(); - Class executorClass = executor.getClass(); - Method[] publicMethods = executorClass.getMethods(); - for (Method method : publicMethods) { - if (method.getReturnType().equals(Void.class)) { - Class[] paramTypes = method.getParameterTypes(); - if (paramTypes.length == 2) { - if (Map.class.isAssignableFrom(paramTypes[0]) - && SvcLogicContext.class.isAssignableFrom(paramTypes[1])) { - methods.put(method.getName(), method); - } - } - } - } - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/test/InterceptLogger.java b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/test/InterceptLogger.java deleted file mode 100644 index 6c81a6c6e..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/java/org/openecomp/appc/test/InterceptLogger.java +++ /dev/null @@ -1,449 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - - -package org.onap.appc.test; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import org.slf4j.Marker; -import ch.qos.logback.classic.Level; - -/** - * This class is used as an intercept logger that can be used in testing to intercept and record all - * messages that are logged, thus allowing a junit test case to examine the log output and make - * assertions. - */ -public class InterceptLogger implements org.slf4j.Logger { - - /** - * This inner class represents an intercepted log event. - */ - public class LogRecord { - private Level level; - private String message; - private long timestamp; - private Throwable t; - - public LogRecord(Level level, String message) { - setLevel(level); - setTimestamp(System.currentTimeMillis()); - setMessage(message); - } - - public LogRecord(Level level, String message, Throwable t) { - this(level, message); - setThrowable(t); - } - - /** - * @return the value of level - */ - public Level getLevel() { - return level; - } - - /** - * @return the value of message - */ - public String getMessage() { - return message; - } - - /** - * @return the value of timestamp - */ - public long getTimestamp() { - return timestamp; - } - - /** - * @param level the value for level - */ - public void setLevel(Level level) { - this.level = level; - } - - /** - * @param message the value for message - */ - public void setMessage(String message) { - this.message = message; - } - - /** - * @param timestamp the value for timestamp - */ - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - /** - * @return the value of t - */ - public Throwable getThrowable() { - return t; - } - - /** - * @param t the value for t - */ - public void setThrowable(Throwable t) { - this.t = t; - } - - } - - /** - * The list of all intercepted log events - */ - private List events; - - /** - * Create the intercept logger - */ - public InterceptLogger() { - events = new ArrayList(1000); - } - - /** - * @return Returns all intercepted log events - */ - public List getLogRecords() { - return events; - } - - /** - * Clears all log events - */ - public void clear() { - events.clear(); - } - - @Override - public void debug(Marker marker, String msg) { - debug(msg); - } - - @Override - public void debug(Marker marker, String format, Object arg) { - debug(MessageFormat.format(format, arg)); - } - - @Override - public void debug(Marker marker, String format, Object... arguments) { - debug(MessageFormat.format(format, arguments)); - } - - @Override - public void debug(Marker marker, String format, Object arg1, Object arg2) { - debug(MessageFormat.format(format, arg1, arg2)); - } - - @Override - public void debug(Marker marker, String msg, Throwable t) { - debug(msg, t); - } - - @Override - public void debug(String msg) { - events.add(new LogRecord(Level.DEBUG, msg)); - } - - @Override - public void debug(String format, Object arg) { - events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arg))); - } - - @Override - public void debug(String format, Object... arguments) { - events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arguments))); - } - - @Override - public void debug(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.DEBUG, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void debug(String msg, Throwable t) { - events.add(new LogRecord(Level.DEBUG, msg, t)); - } - - @Override - public void error(Marker marker, String msg) { - error(msg); - } - - @Override - public void error(Marker marker, String format, Object arg) { - error(format, arg); - } - - @Override - public void error(Marker marker, String format, Object... arguments) { - error(format, arguments); - } - - @Override - public void error(Marker marker, String format, Object arg1, Object arg2) { - error(format, arg1, arg2); - } - - @Override - public void error(Marker marker, String msg, Throwable t) { - events.add(new LogRecord(Level.ERROR, msg, t)); - } - - @Override - public void error(String msg) { - events.add(new LogRecord(Level.ERROR, msg)); - } - - @Override - public void error(String format, Object arg) { - events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arg))); - } - - @Override - public void error(String format, Object... arguments) { - events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arguments))); - } - - @Override - public void error(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.ERROR, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void error(String msg, Throwable t) { - events.add(new LogRecord(Level.ERROR, msg, t)); - } - - @Override - public String getName() { - return null; - } - - @Override - public void info(Marker marker, String msg) { - info(msg); - } - - @Override - public void info(Marker marker, String format, Object arg) { - info(format, arg); - } - - @Override - public void info(Marker marker, String format, Object... arguments) { - info(format, arguments); - } - - @Override - public void info(Marker marker, String format, Object arg1, Object arg2) { - info(format, arg1, arg2); - } - - @Override - public void info(Marker marker, String msg, Throwable t) { - events.add(new LogRecord(Level.INFO, msg, t)); - } - - @Override - public void info(String msg) { - events.add(new LogRecord(Level.INFO, msg)); - } - - @Override - public void info(String format, Object arg) { - events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arg))); - } - - @Override - public void info(String format, Object... arguments) { - events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arguments))); - } - - @Override - public void info(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.INFO, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void info(String msg, Throwable t) { - events.add(new LogRecord(Level.INFO, msg, t)); - } - - @Override - public boolean isDebugEnabled() { - return true; - } - - @Override - public boolean isDebugEnabled(Marker marker) { - return true; - } - - @Override - public boolean isErrorEnabled() { - return true; - } - - @Override - public boolean isErrorEnabled(Marker marker) { - return true; - } - - @Override - public boolean isInfoEnabled() { - return true; - } - - @Override - public boolean isInfoEnabled(Marker marker) { - return true; - } - - @Override - public boolean isTraceEnabled() { - return true; - } - - @Override - public boolean isTraceEnabled(Marker marker) { - return true; - } - - @Override - public boolean isWarnEnabled() { - return true; - } - - @Override - public boolean isWarnEnabled(Marker marker) { - return true; - } - - @Override - public void trace(Marker marker, String msg) { - trace(msg); - } - - @Override - public void trace(Marker marker, String format, Object arg) { - trace(format, arg); - } - - @Override - public void trace(Marker marker, String format, Object... argArray) { - trace(format, argArray); - } - - @Override - public void trace(Marker marker, String format, Object arg1, Object arg2) { - trace(format, arg1, arg2); - } - - @Override - public void trace(Marker marker, String msg, Throwable t) { - trace(msg, t); - } - - @Override - public void trace(String msg) { - events.add(new LogRecord(Level.TRACE, msg)); - } - - @Override - public void trace(String format, Object arg) { - events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arg))); - } - - @Override - public void trace(String format, Object... arguments) { - events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arguments))); - } - - @Override - public void trace(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.TRACE, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void trace(String msg, Throwable t) { - events.add(new LogRecord(Level.TRACE, msg, t)); - } - - @Override - public void warn(Marker marker, String msg) { - warn(msg); - } - - @Override - public void warn(Marker marker, String format, Object arg) { - warn(format, arg); - } - - @Override - public void warn(Marker marker, String format, Object... arguments) { - warn(format, arguments); - } - - @Override - public void warn(Marker marker, String format, Object arg1, Object arg2) { - warn(format, arg1, arg2); - } - - @Override - public void warn(Marker marker, String msg, Throwable t) { - events.add(new LogRecord(Level.WARN, msg, t)); - } - - @Override - public void warn(String msg) { - events.add(new LogRecord(Level.WARN, msg)); - } - - @Override - public void warn(String format, Object arg) { - events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arg))); - } - - @Override - public void warn(String format, Object... arguments) { - events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arguments))); - } - - @Override - public void warn(String format, Object arg1, Object arg2) { - events.add(new LogRecord(Level.WARN, MessageFormat.format(format, arg1, arg2))); - } - - @Override - public void warn(String msg, Throwable t) { - events.add(new LogRecord(Level.WARN, msg, t)); - } -} diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/resources/org/onap/appc/default.properties b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..d63c49143 --- /dev/null +++ b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/resources/org/onap/appc/default.properties @@ -0,0 +1,112 @@ +### +# ============LICENSE_START======================================================= +# ONAP : APPC +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Copyright (C) 2017 Amdocs +# ============================================================================= +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +# ============LICENSE_END========================================================= +### + +# +# Default properties for the APP-C Provider Adapter +# +# ------------------------------------------------------------------------------------------------- +# +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. + +appc.application.name=APPC + +# +# Define the message resource bundle name to be loaded +org.onap.appc.resources=org/onap/appc/i18n/MessageResources +# +# The name of the adapter. +org.onap.appc.provider.adaptor.name=org.onap.appc.appc_provider_adapter +# +# Set up the logging environment +# +org.onap.appc.logging.file=org/onap/appc/logback.xml +org.onap.appc.logging.path=${user.home};etc;../etc +org.onap.appc.logger=org.onap.appc +org.onap.appc.security.logger=org.onap.appc.security +# +# The minimum and maximum provider/tenant context pool sizes. Min=1 means that as soon +# as the provider/tenant is referenced a Context is opened and added to the pool. Max=0 +# means that the upper bound on the pool is unbounded. +org.onap.appc.provider.min.pool=1 +org.onap.appc.provider.max.pool=0 + +# +# The following properties are used to configure the retry logic for connection to the +# IaaS provider(s). The retry delay property is the amount of time, in seconds, the +# application waits between retry attempts. The retry limit is the number of retries +# that are allowed before the request is failed. +org.onap.appc.provider.retry.delay = 30 +org.onap.appc.provider.retry.limit = 10 + +# +# The trusted hosts list for SSL access when a certificate is not provided. +# +provider.trusted.hosts=* +# +# The amount of time, in seconds, to wait for a server state change (start->stop, stop->start, etc). +# If the server does not change state to a valid state within the alloted time, the operation +# fails. +org.onap.appc.server.state.change.timeout=300 +# +# The amount of time to wait, in seconds, between subsequent polls to the OpenStack provider +# to refresh the status of a resource we are waiting on. +# +org.onap.appc.openstack.poll.interval=20 +# +# The connection information to connect to the provider we are using. These properties +# are "structured" properties, in that the name is a compound name, where the nodes +# of the name can be ordered (1, 2, 3, ...). All of the properties with the same ordinal +# position are defining the same entity. For example, provider1.type and provider1.name +# are defining the same provider, whereas provider2.name and provider2.type are defining +# the values for a different provider. Any number of providers can be defined in this +# way. +# + + +# Don't change these 2 right now since they are hard coded in the DG +provider1.type=appc +provider1.name=appc + +#These you can change +provider1.identity=appc +provider1.tenant1.name=appc +provider1.tenant1.userid=appc +provider1.tenant1.password=appc + +# After a change to the provider make sure to recheck these values with an api call to provider1.identity/tokens +test.expected-regions=1 +test.expected-endpoints=1 + +#Your OpenStack IP +test.ip=192.168.1.2 +# Your OpenStack Platform's Keystone Port (default is 5000) +test.port=5000 +test.tenantid=abcde12345fghijk6789lmnopq123rst +test.vmid=abc12345-1234-5678-890a-abcdefg12345 +# Port 8774 below is default port for OpenStack's Nova API Service +test.url=http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345 + diff --git a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/resources/org/openecomp/appc/default.properties b/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/resources/org/openecomp/appc/default.properties deleted file mode 100644 index d63c49143..000000000 --- a/appc-adapters/appc-iaas-adapter/appc-iaas-adapter-bundle/src/test/resources/org/openecomp/appc/default.properties +++ /dev/null @@ -1,112 +0,0 @@ -### -# ============LICENSE_START======================================================= -# ONAP : APPC -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Copyright (C) 2017 Amdocs -# ============================================================================= -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# ============LICENSE_END========================================================= -### - -# -# Default properties for the APP-C Provider Adapter -# -# ------------------------------------------------------------------------------------------------- -# -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. - -appc.application.name=APPC - -# -# Define the message resource bundle name to be loaded -org.onap.appc.resources=org/onap/appc/i18n/MessageResources -# -# The name of the adapter. -org.onap.appc.provider.adaptor.name=org.onap.appc.appc_provider_adapter -# -# Set up the logging environment -# -org.onap.appc.logging.file=org/onap/appc/logback.xml -org.onap.appc.logging.path=${user.home};etc;../etc -org.onap.appc.logger=org.onap.appc -org.onap.appc.security.logger=org.onap.appc.security -# -# The minimum and maximum provider/tenant context pool sizes. Min=1 means that as soon -# as the provider/tenant is referenced a Context is opened and added to the pool. Max=0 -# means that the upper bound on the pool is unbounded. -org.onap.appc.provider.min.pool=1 -org.onap.appc.provider.max.pool=0 - -# -# The following properties are used to configure the retry logic for connection to the -# IaaS provider(s). The retry delay property is the amount of time, in seconds, the -# application waits between retry attempts. The retry limit is the number of retries -# that are allowed before the request is failed. -org.onap.appc.provider.retry.delay = 30 -org.onap.appc.provider.retry.limit = 10 - -# -# The trusted hosts list for SSL access when a certificate is not provided. -# -provider.trusted.hosts=* -# -# The amount of time, in seconds, to wait for a server state change (start->stop, stop->start, etc). -# If the server does not change state to a valid state within the alloted time, the operation -# fails. -org.onap.appc.server.state.change.timeout=300 -# -# The amount of time to wait, in seconds, between subsequent polls to the OpenStack provider -# to refresh the status of a resource we are waiting on. -# -org.onap.appc.openstack.poll.interval=20 -# -# The connection information to connect to the provider we are using. These properties -# are "structured" properties, in that the name is a compound name, where the nodes -# of the name can be ordered (1, 2, 3, ...). All of the properties with the same ordinal -# position are defining the same entity. For example, provider1.type and provider1.name -# are defining the same provider, whereas provider2.name and provider2.type are defining -# the values for a different provider. Any number of providers can be defined in this -# way. -# - - -# Don't change these 2 right now since they are hard coded in the DG -provider1.type=appc -provider1.name=appc - -#These you can change -provider1.identity=appc -provider1.tenant1.name=appc -provider1.tenant1.userid=appc -provider1.tenant1.password=appc - -# After a change to the provider make sure to recheck these values with an api call to provider1.identity/tokens -test.expected-regions=1 -test.expected-endpoints=1 - -#Your OpenStack IP -test.ip=192.168.1.2 -# Your OpenStack Platform's Keystone Port (default is 5000) -test.port=5000 -test.tenantid=abcde12345fghijk6789lmnopq123rst -test.vmid=abc12345-1234-5678-890a-abcdefg12345 -# Port 8774 below is default port for OpenStack's Nova API Service -test.url=http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345 - -- cgit