From 0d3e9ace323660381350a884b08ed92aa2290dbd Mon Sep 17 00:00:00 2001 From: Huang Haibin Date: Tue, 10 Jul 2018 19:22:34 +0800 Subject: Add Openstack Pike plugin framework Add Pike framework and one function extension Add Vagrant for test Change-Id: I045ac1f1a920b509a69d7a72f8e60fb108102839 Issue-ID: MULTICLOUD-276 Signed-off-by: Huang Haibin --- pike/pike/extensions/__init__.py | 14 ++++++ pike/pike/extensions/tests/__init__.py | 14 ++++++ pike/pike/extensions/tests/test_epacaps.py | 67 +++++++++++++++++++++++++++ pike/pike/extensions/tests/test_extensions.py | 45 ++++++++++++++++++ pike/pike/extensions/urls.py | 26 +++++++++++ pike/pike/extensions/views/__init__.py | 14 ++++++ pike/pike/extensions/views/epacaps.py | 33 +++++++++++++ pike/pike/extensions/views/extensions.py | 29 ++++++++++++ 8 files changed, 242 insertions(+) create mode 100644 pike/pike/extensions/__init__.py create mode 100644 pike/pike/extensions/tests/__init__.py create mode 100644 pike/pike/extensions/tests/test_epacaps.py create mode 100644 pike/pike/extensions/tests/test_extensions.py create mode 100644 pike/pike/extensions/urls.py create mode 100644 pike/pike/extensions/views/__init__.py create mode 100644 pike/pike/extensions/views/epacaps.py create mode 100644 pike/pike/extensions/views/extensions.py (limited to 'pike/pike/extensions') diff --git a/pike/pike/extensions/__init__.py b/pike/pike/extensions/__init__.py new file mode 100644 index 00000000..afa702d3 --- /dev/null +++ b/pike/pike/extensions/__init__.py @@ -0,0 +1,14 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# 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. + diff --git a/pike/pike/extensions/tests/__init__.py b/pike/pike/extensions/tests/__init__.py new file mode 100644 index 00000000..afa702d3 --- /dev/null +++ b/pike/pike/extensions/tests/__init__.py @@ -0,0 +1,14 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# 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. + diff --git a/pike/pike/extensions/tests/test_epacaps.py b/pike/pike/extensions/tests/test_epacaps.py new file mode 100644 index 00000000..40f8d3a7 --- /dev/null +++ b/pike/pike/extensions/tests/test_epacaps.py @@ -0,0 +1,67 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# 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. + +import json + +import mock +from django.test import Client +from rest_framework import status +import unittest + +from newton_base.util import VimDriverUtils + +MOCK_VIM_INFO = { + "createTime": "2017-04-01 02:22:27", + "domain": "Default", + "name": "TiS_R4", + "password": "admin", + "tenant": "admin", + "type": "openstack", + "url": "http://128.224.180.14:5000/v3", + "userName": "admin", + "vendor": "WindRiver", + "version": "pike", + "vimId": "windriver-hudson-dc_RegionOne", + 'cloud_owner':'windriver-hudson-dc', + 'cloud_region_id':'RegionOne', + 'cloud_extra_info':'', + 'cloud_epa_caps':'{"huge_page":"true","cpu_pinning":"true",\ + "cpu_thread_policy":"true","numa_aware":"true","sriov":"true",\ + "dpdk_vswitch":"true","rdt":"false","numa_locality_pci":"true"}', + 'insecure':'True', +} + + +class TestEpaCaps(unittest.TestCase): + def setUp(self): + self.client = Client() + + @mock.patch.object(VimDriverUtils, 'get_vim_info') + def test_get_epa_caps_info(self, mock_get_vim_info): + mock_get_vim_info.return_value = MOCK_VIM_INFO + cloud_owner = "windriver-hudson-dc" + cloud_region_id = "RegionOne" + vimid = cloud_owner + "_" + cloud_region_id + + response = self.client.get( + "/api/multicloud-pike/v0/" + vimid + "/extensions/epa-caps") + json_content = response.json() + + self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEquals(4, len(json_content.keys())) + self.assertEquals(cloud_owner, json_content["cloud-owner"]) + self.assertEquals(cloud_region_id, json_content["cloud-region-id"]) + self.assertEquals(vimid, json_content["vimid"]) + self.assertEquals(json.loads(MOCK_VIM_INFO['cloud_epa_caps']), + json_content["cloud-epa-caps"]) diff --git a/pike/pike/extensions/tests/test_extensions.py b/pike/pike/extensions/tests/test_extensions.py new file mode 100644 index 00000000..3842d4b7 --- /dev/null +++ b/pike/pike/extensions/tests/test_extensions.py @@ -0,0 +1,45 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# 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. + +from django.test import Client +from rest_framework import status +import unittest + + +class TestExtensions(unittest.TestCase): + def setUp(self): + self.client = Client() + + def test_get_extensions_info(self): + cloud_owner = "windriver-hudson-dc" + cloud_region_id = "RegionOne" + vimid = cloud_owner + "_" + cloud_region_id + + response = self.client.get( + "/api/multicloud-pike/v0/" + vimid + "/extensions/") + json_content = response.json() + + self.assertEquals(status.HTTP_200_OK, response.status_code) + self.assertEquals(4, len(json_content.keys())) + + self.assertEquals(cloud_owner, json_content["cloud-owner"]) + self.assertEquals(cloud_region_id, json_content["cloud-region-id"]) + self.assertEquals(vimid, json_content["vimid"]) + + self.assertEquals("epa-caps", json_content["extensions"][0]["alias"]) + self.assertEquals("Multiple network support", json_content["extensions"][0]["description"]) + self.assertEquals("EPACapsQuery", json_content["extensions"][0]["name"]) + self.assertEquals("http://127.0.0.1:80/api/multicloud-pike/v0/%s/extensions/epa-caps" % vimid, + json_content["extensions"][0]["url"]) + self.assertEquals("", json_content["extensions"][0]["spec"]) diff --git a/pike/pike/extensions/urls.py b/pike/pike/extensions/urls.py new file mode 100644 index 00000000..545dec98 --- /dev/null +++ b/pike/pike/extensions/urls.py @@ -0,0 +1,26 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# 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. + +from django.conf.urls import url +from rest_framework.urlpatterns import format_suffix_patterns + +from pike.extensions.views import extensions +from pike.extensions.views import epacaps + +urlpatterns = [ + url(r'^sions/?$', extensions.Extensions.as_view()), + url(r'^sions/epa-caps/?$', epacaps.EpaCaps.as_view()), +] + +urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/pike/pike/extensions/views/__init__.py b/pike/pike/extensions/views/__init__.py new file mode 100644 index 00000000..afa702d3 --- /dev/null +++ b/pike/pike/extensions/views/__init__.py @@ -0,0 +1,14 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# 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. + diff --git a/pike/pike/extensions/views/epacaps.py b/pike/pike/extensions/views/epacaps.py new file mode 100644 index 00000000..025d55df --- /dev/null +++ b/pike/pike/extensions/views/epacaps.py @@ -0,0 +1,33 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# 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. + +import logging +import json +import traceback + +from django.conf import settings + + +from newton_base.extensions import epacaps as newton_epacaps + +logger = logging.getLogger(__name__) + +# DEBUG=True + + +class EpaCaps(newton_epacaps.EpaCaps): + + def __init__(self): + self.proxy_prefix = settings.MULTICLOUD_PREFIX + self._logger = logger diff --git a/pike/pike/extensions/views/extensions.py b/pike/pike/extensions/views/extensions.py new file mode 100644 index 00000000..2c499f36 --- /dev/null +++ b/pike/pike/extensions/views/extensions.py @@ -0,0 +1,29 @@ +# Copyright (c) 2017-2018 Wind River Systems, Inc. +# +# 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. + +import logging + +from django.conf import settings +from newton_base.extensions import extensions as newton_extensions + +logger = logging.getLogger(__name__) + +# DEBUG=True + +class Extensions(newton_extensions.Extensions): + + def __init__(self): + self._logger = logger + self.proxy_prefix = settings.MULTICLOUD_PREFIX + -- cgit 1.2.3-korg