commit
7e8a7351fa
@ -0,0 +1,83 @@
|
||||
# Copyright (C) 2021 FUJITSU
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 tacker.tests.unit import base
|
||||
from tacker.vnfm.infra_drivers.kubernetes.k8s import tosca_kube_object
|
||||
|
||||
|
||||
class TestToscaKubeObject(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestToscaKubeObject, self).setUp()
|
||||
self.tosca_kube_object = tosca_kube_object.ToscaKubeObject(
|
||||
name='name',
|
||||
namespace='namespace',
|
||||
mapping_ports='mappingports',
|
||||
containers=[
|
||||
tosca_kube_object.Container(
|
||||
name="name")],
|
||||
network_name="network",
|
||||
mgmt_connection_point=True,
|
||||
scaling_object=[
|
||||
tosca_kube_object.ScalingObject(
|
||||
scale_target_name='scalingname')],
|
||||
service_type='servicetype',
|
||||
labels={
|
||||
'lable': 'lable'},
|
||||
annotations="annotations")
|
||||
|
||||
def test_tosca_kube_object(self):
|
||||
self.assertEqual('name', self.tosca_kube_object.name)
|
||||
self.assertEqual('namespace', self.tosca_kube_object.namespace)
|
||||
|
||||
|
||||
class TestContainerObject(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestContainerObject, self).setUp()
|
||||
self.container_object = tosca_kube_object.Container(
|
||||
name='container',
|
||||
num_cpus=1,
|
||||
mem_size="100MB",
|
||||
image="ubuntu",
|
||||
command='command',
|
||||
args=['args'],
|
||||
ports=['22'],
|
||||
config='config'
|
||||
)
|
||||
|
||||
def test_container_object(self):
|
||||
self.assertEqual('container', self.container_object.name)
|
||||
self.assertEqual(1, self.container_object.num_cpus)
|
||||
self.assertEqual('100MB', self.container_object.mem_size)
|
||||
self.assertEqual('ubuntu', self.container_object.image)
|
||||
|
||||
|
||||
class TestScalingObject(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestScalingObject, self).setUp()
|
||||
self.scaling_object = tosca_kube_object.ScalingObject(
|
||||
scaling_name='scalingname',
|
||||
min_replicas=1,
|
||||
max_replicas=3,
|
||||
scale_target_name="cp1",
|
||||
target_cpu_utilization_percentage="40"
|
||||
)
|
||||
|
||||
def test_scaling_object(self):
|
||||
self.assertEqual('scalingname', self.scaling_object.scaling_name)
|
||||
self.assertEqual(1, self.scaling_object.min_replicas)
|
||||
self.assertEqual(3, self.scaling_object.max_replicas)
|
||||
self.assertEqual("cp1", self.scaling_object.scale_target_name)
|
||||
self.assertEqual(
|
||||
"40", self.scaling_object.target_cpu_utilization_percentage)
|
@ -0,0 +1,88 @@
|
||||
# Copyright (C) 2020 FUJITSU
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 os
|
||||
|
||||
from tacker.tests.unit import base
|
||||
from tacker.tests.unit.vnfm.infra_drivers.kubernetes import fakes
|
||||
from tacker.vnfm.infra_drivers.kubernetes.k8s import translate_inputs
|
||||
|
||||
|
||||
class TestParser(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestParser, self).setUp()
|
||||
self.k8s_client_dict = fakes.fake_k8s_client_dict()
|
||||
self.vnfd_path = '../../../../etc/samples/sample_tosca_vnfc.yaml'
|
||||
self.yaml_path = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
self.vnfd_path)
|
||||
self.vnfd_dict = {
|
||||
"tosca_definitions_version": "tosca_simple_profile_for_nfv_1_0_0",
|
||||
"description": "Demo example",
|
||||
"metadata": {
|
||||
"template_name": "sample-tosca-vnfd"},
|
||||
"topology_template": {
|
||||
"node_templates": {
|
||||
"VDU1": {
|
||||
"type": "tosca.nodes.nfv.VDU.Tacker",
|
||||
"capabilities": {
|
||||
"nfv_compute": {
|
||||
"properties": {
|
||||
"num_cpus": 1,
|
||||
"mem_size": "512 MB",
|
||||
"disk_size": "1 GB"}}},
|
||||
"properties": {
|
||||
"vnfcs": {
|
||||
"web_server": {
|
||||
"mem_size": "100 MB",
|
||||
"config": "config"
|
||||
}
|
||||
},
|
||||
"labels": [
|
||||
"label1:1", "label2:2"
|
||||
]
|
||||
}
|
||||
},
|
||||
"CP1": {
|
||||
"type": "tosca.nodes.nfv.CP.Tacker",
|
||||
"properties": {
|
||||
"order": 0,
|
||||
"management": True,
|
||||
"anti_spoofing_protection": False},
|
||||
"requirements": [
|
||||
{"virtualLink": {
|
||||
"node": "VL1"}},
|
||||
{"virtualBinding": {
|
||||
"node": "VDU1"}}]},
|
||||
"VL1": {
|
||||
"type": "tosca.nodes.nfv.VL",
|
||||
"properties": {
|
||||
"vendor": "Tacker",
|
||||
"network_name": "net_mgmt"}}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.parser = translate_inputs.Parser(self.vnfd_dict)
|
||||
|
||||
def test_loader(self):
|
||||
tosca_kube_object = self.parser.loader()
|
||||
self.assertEqual(tosca_kube_object[0].name[:8], "svc-VDU1")
|
||||
self.assertEqual(tosca_kube_object[0].containers[0].name, "web_server")
|
||||
self.assertEqual(
|
||||
tosca_kube_object[0].containers[0].mem_size,
|
||||
100000000)
|
||||
self.assertEqual(
|
||||
tosca_kube_object[0].labels, {
|
||||
'label1': '1', 'label2': '2'})
|
@ -0,0 +1,89 @@
|
||||
# Copyright (C) 2021 FUJITSU
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 kubernetes import client
|
||||
from unittest import mock
|
||||
|
||||
|
||||
from tacker.tests.unit import base
|
||||
from tacker.vnfm.infra_drivers.kubernetes.k8s import translate_outputs
|
||||
from tacker.vnfm.infra_drivers.kubernetes import translate_template
|
||||
|
||||
|
||||
class TestTOSCAToKubernetes(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestTOSCAToKubernetes, self).setUp()
|
||||
self.vnf = {
|
||||
"vnfd": {
|
||||
"service_types": [
|
||||
{
|
||||
"service_type": "vnfd",
|
||||
"id": "ca0d8667-ce35-4f7a-9744-ac4bc7d5579d"
|
||||
}
|
||||
],
|
||||
"description": "Sample",
|
||||
"tenant_id": "689708956a2d4ae0a27120d3aca6a560",
|
||||
"created_at": "2016-10-20 07:38:54",
|
||||
"updated_at": None,
|
||||
"attributes": {
|
||||
"vnfd":
|
||||
"description: "
|
||||
"Demo example\nmetadata: "
|
||||
"{template_name: sample-tosca-vnfd}\n"
|
||||
"topology_template:\n "
|
||||
"node_templates:\n CP1:\n "
|
||||
"properties: {anti_spoofing_protection: "
|
||||
"false, management: true, order: 0}\n "
|
||||
"requirements:\n "
|
||||
"- virtualLink: {node: VL1}\n "
|
||||
"- virtualBinding: {node: VDU1}\n "
|
||||
"type: tosca.nodes.nfv.CP.Tacker\n "
|
||||
"VDU1:\n "
|
||||
"capabilities:\n "
|
||||
"nfv_compute:\n "
|
||||
"properties: {disk_size: 1 GB, "
|
||||
"mem_size: 512 MB, num_cpus: 1}\n "
|
||||
"properties: {mapping_ports: [80:80] , "
|
||||
"vnfcs: {web:{mem_size: 100 MB, "
|
||||
"config: param0:key1}}}\n "
|
||||
"type: tosca.nodes.nfv.VDU.Tacker\n "
|
||||
"VL1:\n properties: {network_name: "
|
||||
"net_mgmt, vendor: Tacker}\n "
|
||||
"type: tosca.nodes.nfv.VL\ntosca_definitions_version: "
|
||||
"tosca_simple_profile_for_nfv_1_0_0\n"
|
||||
},
|
||||
"id": "0fb827e7-32b0-4e5b-b300-e1b1dce8a831",
|
||||
"name": "vnfd-sample",
|
||||
"template_source": "onboarded or inline"
|
||||
}
|
||||
}
|
||||
|
||||
self.core_v1_api_client = client.CoreV1Api
|
||||
self.app_v1_api_client = client.AppsV1Api
|
||||
self.scaling_api_client = client.AutoscalingApi
|
||||
self.tosca_to_kubernetes_object = translate_template.TOSCAToKubernetes(
|
||||
self.vnf, self.core_v1_api_client, self.app_v1_api_client,
|
||||
self.scaling_api_client)
|
||||
|
||||
def test_generate_tosca_kube_objects(self):
|
||||
result = self.tosca_to_kubernetes_object.generate_tosca_kube_objects()
|
||||
self.assertEqual(result[0].name[:8], "svc-VDU1")
|
||||
self.assertEqual(result[0].containers[0].name, "web")
|
||||
self.assertEqual(result[0].containers[0].mem_size, 100000000)
|
||||
|
||||
@mock.patch.object(translate_outputs.Transformer, 'deploy')
|
||||
def test_deploy_kuberentes_objects(self, mock_deploy):
|
||||
mock_deploy.return_value = "name, namespace"
|
||||
self.tosca_to_kubernetes_object.deploy_kubernetes_objects()
|
Loading…
Reference in new issue