summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--newton/assembly.xml8
-rw-r--r--newton/docker/Dockerfile30
-rwxr-xr-xnewton/docker/build-image.sh32
-rw-r--r--newton/newton/proxy/tests/test_service_proxy.py3
-rw-r--r--newton/newton/proxy/views/services.py59
-rw-r--r--newton/newton/pub/utils/restcall.py20
-rw-r--r--newton/newton/registration/views/registration.py8
-rw-r--r--newton/pom.xml52
-rwxr-xr-xnewton/run.sh20
-rwxr-xr-xnewton/stop.sh3
10 files changed, 192 insertions, 43 deletions
diff --git a/newton/assembly.xml b/newton/assembly.xml
index 89f1a954..c478ea25 100644
--- a/newton/assembly.xml
+++ b/newton/assembly.xml
@@ -38,6 +38,14 @@
</includes>
</fileSet>
<fileSet>
+ <directory>docker</directory>
+ <outputDirectory>/docker</outputDirectory>
+ <includes>
+ <include>*.sh</include>
+ <include>Dockerfile</include>
+ </includes>
+ </fileSet>
+ <fileSet>
<directory>.</directory>
<outputDirectory>/</outputDirectory>
<includes>
diff --git a/newton/docker/Dockerfile b/newton/docker/Dockerfile
new file mode 100644
index 00000000..51379089
--- /dev/null
+++ b/newton/docker/Dockerfile
@@ -0,0 +1,30 @@
+FROM python:2
+
+ARG HTTP_PROXY=${HTTP_PROXY}
+ARG HTTPS_PROXY=${HTTPS_PROXY}
+
+ENV http_proxy $HTTP_PROXY
+ENV https_proxy $HTTPS_PROXY
+
+ENV MSB_ADDR "127.0.0.1"
+ENV MSB_PORT "80"
+ENV AAI_ADDR "aai.api.simpledemo.openecomp.org"
+ENV AAI_PORT "8443"
+ENV AAI_SCHEMA_VERSION "v11"
+ENV AAI_USERNAME "AAI"
+ENV AAI_PASSWORD "AAI"
+
+EXPOSE 9003
+
+# COPY ./ /opt/newton/
+RUN apt-get update && \
+ apt-get install -y memcached && \
+ apt-get install -y unzip && \
+ cd /opt/ && \
+ wget -O multicloud-openstack-newton.zip "https://nexus.onap.org/service/local/artifact/maven/redirect?r=snapshots&g=org.onap.multicloud.openstack&a=multicloud-openstack-newton&e=zip&v=LATEST" && \
+ unzip -q -o -B multicloud-openstack-newton.zip && \
+ rm -f multicloud-openstack-newton.zip && \
+ pip install -r /opt/newton/requirements.txt
+
+WORKDIR /opt/newton
+CMD /bin/sh -c /opt/newton/run.sh
diff --git a/newton/docker/build-image.sh b/newton/docker/build-image.sh
new file mode 100755
index 00000000..fd8fb8cd
--- /dev/null
+++ b/newton/docker/build-image.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+DIRNAME=`dirname $0`
+DOCKER_BUILD_DIR=`cd $DIRNAME/; pwd`
+echo "DOCKER_BUILD_DIR=${DOCKER_BUILD_DIR}"
+cd ${DOCKER_BUILD_DIR}
+
+BUILD_ARGS="--no-cache"
+ORG="onap"
+VERSION="1.0.0-SNAPSHOT"
+PROJECT="multicloud"
+IMAGE="openstack-newton"
+DOCKER_REPOSITORY="nexus3.onap.org:10003"
+IMAGE_NAME="${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/${IMAGE}"
+
+if [ $HTTP_PROXY ]; then
+ BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
+fi
+if [ $HTTPS_PROXY ]; then
+ BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
+fi
+
+function build_image {
+ docker build ${BUILD_ARGS} -t ${IMAGE_NAME}:${VERSION} -t ${IMAGE_NAME}:latest .
+}
+
+function push_image {
+ docker push ${IMAGE_NAME}:${VERSION}
+ docker push ${IMAGE_NAME}:latest
+}
+
+build_image
+push_image
diff --git a/newton/newton/proxy/tests/test_service_proxy.py b/newton/newton/proxy/tests/test_service_proxy.py
index e9f2691d..2dd558d5 100644
--- a/newton/newton/proxy/tests/test_service_proxy.py
+++ b/newton/newton/proxy/tests/test_service_proxy.py
@@ -698,6 +698,7 @@ MOCK_PATCH_IMAGE_RESPONSE = {
class mock_get_servers_response_specs(object):
status_code = 200
+ content = ''
def json(self):
pass
@@ -735,6 +736,7 @@ class TestServiceProxy(unittest.TestCase):
mock_session = mock.Mock(name='mock_session', spec=mock_session_specs)
mock_get_servers_response_obj = mock.Mock(spec=mock_get_servers_response_specs)
mock_get_servers_response_obj.status_code=200
+ mock_get_servers_response_obj.content = MOCK_GET_SERVERS_RESPONSE
mock_get_servers_response_obj.json.return_value=MOCK_GET_SERVERS_RESPONSE
mock_session.get.return_value = mock_get_servers_response_obj
@@ -782,6 +784,7 @@ class TestServiceProxy(unittest.TestCase):
mock_session = mock.Mock(name='mock_session', spec=mock_session_specs)
mock_post_server_response_obj = mock.Mock(spec=mock_get_servers_response_specs)
mock_post_server_response_obj.status_code=202
+ mock_post_server_response_obj.content = MOCK_POST_SERVER_RESPONSE
mock_post_server_response_obj.json.return_value=MOCK_POST_SERVER_RESPONSE
mock_session.post.return_value = mock_post_server_response_obj
diff --git a/newton/newton/proxy/views/services.py b/newton/newton/proxy/views/services.py
index 1a478f35..85de3aa6 100644
--- a/newton/newton/proxy/views/services.py
+++ b/newton/newton/proxy/views/services.py
@@ -72,7 +72,8 @@ class Services(APIView):
resp = sess.head(req_resource, endpoint_filter=service)
#update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
+ content = resp.json() if resp.content else None
+
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
#return resp
except VimDriverNewtonException as e:
@@ -142,13 +143,13 @@ class Services(APIView):
resp = sess.get(req_resource, endpoint_filter=service)
#update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
-
- #filter the resp content and replace all endpoint prefix
- tmp_content = json.dumps(content)
- tmp_pattern = re.compile(real_prefix)
- tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
- content = json.loads(tmp_content)
+ content = resp.json() if resp.content else None
+ if content:
+ #filter the resp content and replace all endpoint prefix
+ tmp_content = json.dumps(content)
+ tmp_pattern = re.compile(real_prefix)
+ tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
+ content = json.loads(tmp_content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
#return resp
@@ -220,13 +221,13 @@ class Services(APIView):
resp = sess.post(req_resource, data=json.JSONEncoder().encode(request.data),endpoint_filter=service)
# update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
-
- #filter the resp content and replace all endpoint prefix
- tmp_content = json.dumps(content)
- tmp_pattern = re.compile(real_prefix)
- tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
- content = json.loads(tmp_content)
+ content = resp.json() if resp.content else None
+ if content:
+ #filter the resp content and replace all endpoint prefix
+ tmp_content = json.dumps(content)
+ tmp_pattern = re.compile(real_prefix)
+ tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
+ content = json.loads(tmp_content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
@@ -298,13 +299,13 @@ class Services(APIView):
resp = sess.put(req_resource, data=json.JSONEncoder().encode(request.data),endpoint_filter=service)
# update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
-
- #filter the resp content and replace all endpoint prefix
- tmp_content = json.dumps(content)
- tmp_pattern = re.compile(real_prefix)
- tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
- content = json.loads(tmp_content)
+ content = resp.json() if resp.content else None
+ if content:
+ #filter the resp content and replace all endpoint prefix
+ tmp_content = json.dumps(content)
+ tmp_pattern = re.compile(real_prefix)
+ tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
+ content = json.loads(tmp_content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
@@ -377,13 +378,13 @@ class Services(APIView):
resp = sess.patch(req_resource, data=json.JSONEncoder().encode(request.data),endpoint_filter=service)
# update token cache in case the token was required during the requests
tmp_auth_token = VimDriverUtils.update_token_cache(vim, sess, tmp_auth_token, tmp_auth_state)
- content = resp.json()
-
- #filter the resp content and replace all endpoint prefix
- tmp_content = json.dumps(content)
- tmp_pattern = re.compile(real_prefix)
- tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
- content = json.loads(tmp_content)
+ content = resp.json() if resp.content else None
+ if content:
+ #filter the resp content and replace all endpoint prefix
+ tmp_content = json.dumps(content)
+ tmp_pattern = re.compile(real_prefix)
+ tmp_content = tmp_pattern.sub(proxy_prefix, tmp_content)
+ content = json.loads(tmp_content)
return Response(headers={'X-Subject-Token': tmp_auth_token}, data=content, status=resp.status_code)
diff --git a/newton/newton/pub/utils/restcall.py b/newton/newton/pub/utils/restcall.py
index 04b5a6f8..a2838680 100644
--- a/newton/newton/pub/utils/restcall.py
+++ b/newton/newton/pub/utils/restcall.py
@@ -71,18 +71,24 @@ def call_req(base_url, user, passwd, auth_type,
else:
ret = [1, resp_body, resp_status]
break
- except http.client.ResponseNotReady:
-# logger.debug("retry_times=%d", retry_times)
- ret = [1, "Unable to connect to %s" % full_url, resp_status]
- continue
+ except Exception as ex:
+ if 'httplib.ResponseNotReady' in str(sys.exc_info()):
+ logger.debug("retry_times=%d", retry_times)
+ logger.error(traceback.format_exc())
+ ret = [1, "Unable to connect to %s" % full_url, resp_status]
+ continue
+ raise ex
except urllib.error.URLError as err:
ret = [2, str(err), resp_status]
- except Exception:
+ except Exception as ex:
logger.error(traceback.format_exc())
logger.error("[%s]ret=%s" % (callid, str(sys.exc_info())))
if not resp_status:
resp_status = status.HTTP_500_INTERNAL_SERVER_ERROR
ret = [3, str(sys.exc_info()), resp_status]
+ except:
+ logger.error(traceback.format_exc())
+ ret = [4, str(sys.exc_info()), resp_status]
# logger.debug("[%s]ret=%s" % (callid, str(ret)))
return ret
@@ -100,7 +106,7 @@ def req_to_vim(base_url, resource, method, extra_headers='', content=''):
resource, method, extra_headers, content)
def req_to_aai(resource, method, content='', appid=config.MULTICLOUD_APP_ID):
- tmp_trasaction_id = uuid.uuid1()
+ tmp_trasaction_id = str(uuid.uuid1())
headers = {
'X-FromAppId': appid,
'X-TransactionId': tmp_trasaction_id,
@@ -110,7 +116,7 @@ def req_to_aai(resource, method, content='', appid=config.MULTICLOUD_APP_ID):
logger.debug("req_to_aai--%s::> %s, %s" % (tmp_trasaction_id, method, resource))
return call_req(config.AAI_BASE_URL, config.AAI_USERNAME, config.AAI_PASSWORD, rest_no_auth,
- resource, method, json.dumps(content), headers)
+ resource, method, content=json.dumps(content), extra_headers=headers)
def combine_url(base_url, resource):
diff --git a/newton/newton/registration/views/registration.py b/newton/newton/registration/views/registration.py
index fa388b73..131a58e0 100644
--- a/newton/newton/registration/views/registration.py
+++ b/newton/newton/registration/views/registration.py
@@ -387,7 +387,7 @@ class Registry(APIView):
ret = self.update_az(cloud_owner, cloud_region_id, vg_info)
if ret != 0:
# failed to update image
- self._logger.debug("failed to populate az info into AAI: %s, volume-group-id: %s, ret:%s"
+ self._logger.debug("failed to populate volumegroup info into AAI: %s, volume-group-id: %s, ret:%s"
% (vimid, vg_info['volume-group-id'], ret))
continue
pass
@@ -454,7 +454,7 @@ class Registry(APIView):
ret = self.update_az(cloud_owner, cloud_region_id, snapshot_info)
if ret != 0:
# failed to update image
- self._logger.debug("failed to populate az info into AAI: %s, snapshot-id: %s, ret:%s"
+ self._logger.debug("failed to populate snapshot info into AAI: %s, snapshot-id: %s, ret:%s"
% (vimid, snapshot_info['snapshot-id'], ret))
continue
pass
@@ -554,7 +554,7 @@ class Registry(APIView):
req_to_aai("/cloud-infrastructure/pservers/pserver/%s/relationship-list/relationship"
% (pserverinfo['hostname']), "PUT", content=relationship_data)
- self._logger.debug("update_snapshot,vimid:%s_%s req_to_aai: %s, return %s, %s, %s"
+ self._logger.debug("update_pserver,vimid:%s_%s req_to_aai: %s, return %s, %s, %s"
% (cloud_owner, cloud_region_id, pserverinfo['hostname'], retcode, content,
status_code))
pass
@@ -578,7 +578,7 @@ class Registry(APIView):
for hypervisor in content.get('hypervisors'):
hypervisor_info = {
'hostname': hypervisor['hypervisor_hostname'],
- 'in-maint': hypervisor['name'],
+ 'in-maint': hypervisor['state'],
'pserver-id': hypervisor.get('id'),
'ptnii-equip-name': hypervisor.get('id'),
diff --git a/newton/pom.xml b/newton/pom.xml
index e1989492..555f3b53 100644
--- a/newton/pom.xml
+++ b/newton/pom.xml
@@ -11,7 +11,10 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.onap.oparent</groupId>
<artifactId>oparent</artifactId>
@@ -47,4 +50,51 @@
</plugin>
</plugins>
</build>
+ <profiles>
+ <profile>
+ <id>docker</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>0.16.5</version>
+ <inherited>false</inherited>
+ <configuration>
+ <images>
+ <image>
+ <name>onap/multicloud/multicloud-openstack-newton</name>
+ <build>
+ <cleanup>try</cleanup>
+ <dockerFileDir>${basedir}/docker/</dockerFileDir>
+ <dockerFile>${basedir}/docker/Dockerfile</dockerFile>
+ <tags>
+ <tag>${project.version}-STAGING-latest</tag>
+ </tags>
+ </build>
+ </image>
+ </images>
+ </configuration>
+ <executions>
+ <execution>
+ <id>generate-images</id>
+ <phase>package</phase>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>push-images</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>build</goal>
+ <goal>push</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/newton/run.sh b/newton/run.sh
index 8b8b0890..763f72d7 100755
--- a/newton/run.sh
+++ b/newton/run.sh
@@ -10,4 +10,22 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-nohup python manage.py runserver 127.0.0.1:9003 > /dev/null &
+#!/bin/bash
+
+sed -i "s/MSB_SERVICE_ADDR =.*/MSB_SERVICE_ADDR = \"${MSB_ADDR}\"/g" newton/pub/config/config.py
+sed -i "s/MSB_SERVICE_PORT =.*/MSB_SERVICE_PORT = \"${MSB_PORT}\"/g" newton/pub/config/config.py
+sed -i "s/AAI_ADDR =.*/AAI_ADDR = \"${AAI_ADDR}\"/g" newton/pub/config/config.py
+sed -i "s/AAI_PORT =.*/AAI_PORT = \"${AAI_PORT}\"/g" newton/pub/config/config.py
+sed -i "s/AAI_SCHEMA_VERSION =.*/AAI_SCHEMA_VERSION = \"${AAI_SCHEMA_VERSION}\"/g" newton/pub/config/config.py
+sed -i "s/AAI_USERNAME =.*/AAI_USERNAME = \"${AAI_USERNAME}\"/g" newton/pub/config/config.py
+sed -i "s/AAI_PASSWORD =.*/AAI_PASSWORD = \"${AAI_PASSWORD}\"/g" newton/pub/config/config.py
+
+memcached -d -m 2048 -u root -c 1024 -p 11211 -P /tmp/memcached1.pid
+
+nohup python manage.py runserver 0.0.0.0:9003 2>&1 &
+
+while [ ! -f logs/runtime_newton.log ]; do
+ sleep 1
+done
+
+tail -F logs/runtime_newton.log
diff --git a/newton/stop.sh b/newton/stop.sh
index db6d7366..1abfe404 100755
--- a/newton/stop.sh
+++ b/newton/stop.sh
@@ -10,4 +10,5 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-ps auxww | grep 'manage.py runserver 127.0.0.1:9003' | awk '{print $2}' | xargs kill -9
+ps auxww | grep 'manage.py runserver 0.0.0.0:9003' | awk '{print $2}' | xargs kill -9
+ps auxww | grep 'memcached -d -m 2048 -u root -c 1024 -p 11211 -P /tmp/memcached1.pid' | awk '{print $2}' | xargs kill -9