+++ /dev/null
-# -*- coding: utf-8 -*-
-
-##
-# Copyright 2017 Intel Corporation.
-#
-# 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.
-#
-# For those usages not covered by the Apache License, Version 2.0 please
-# contact with: nfvlabs@tid.es
-##
-
-"""
-This module contains unit tests for the OpenStack VIM connector
-Run this directly with python2 or python3.
-"""
-
-import copy
-import unittest
-
-import mock
-from neutronclient.v2_0.client import Client
-
-from osm_ro import vimconn
-from osm_ro.vimconn_openstack import vimconnector
-
-
-__author__ = "Igor D.C."
-__date__ = "$23-aug-2017 23:59:59$"
-
-
-class TestSfcOperations(unittest.TestCase):
- def setUp(self):
- # instantiate dummy VIM connector so we can test it
- self.vimconn = vimconnector(
- '123', 'openstackvim', '456', '789', 'http://dummy.url', None,
- 'user', 'pass')
-
- def _test_new_sfi(self, create_port_pair, sfc_encap,
- ingress_ports=['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
- egress_ports=['230cdf1b-de37-4891-bc07-f9010cf1f967']):
- # input to VIM connector
- name = 'osm_sfi'
- # + ingress_ports
- # + egress_ports
- # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
- correlation = 'mpls'
- if sfc_encap is not None:
- if not sfc_encap:
- correlation = None
-
- # what OpenStack is assumed to respond (patch OpenStack's return value)
- dict_from_neutron = {'port_pair': {
- 'id': '3d7ddc13-923c-4332-971e-708ed82902ce',
- 'name': name,
- 'description': '',
- 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
- 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
- 'ingress': ingress_ports[0] if len(ingress_ports) else None,
- 'egress': egress_ports[0] if len(egress_ports) else None,
- 'service_function_parameters': {'correlation': correlation}
- }}
- create_port_pair.return_value = dict_from_neutron
-
- # what the VIM connector is expected to
- # send to OpenStack based on the input
- dict_to_neutron = {'port_pair': {
- 'name': name,
- 'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'egress': '230cdf1b-de37-4891-bc07-f9010cf1f967',
- 'service_function_parameters': {'correlation': correlation}
- }}
-
- # call the VIM connector
- if sfc_encap is None:
- result = self.vimconn.new_sfi(name, ingress_ports, egress_ports)
- else:
- result = self.vimconn.new_sfi(name, ingress_ports, egress_ports,
- sfc_encap)
-
- # assert that the VIM connector made the expected call to OpenStack
- create_port_pair.assert_called_with(dict_to_neutron)
- # assert that the VIM connector had the expected result / return value
- self.assertEqual(result, dict_from_neutron['port_pair']['id'])
-
- def _test_new_sf(self, create_port_pair_group):
- # input to VIM connector
- name = 'osm_sf'
- instances = ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd',
- '12ba215e-3987-4892-bd3a-d0fd91eecf98',
- 'e25a7c79-14c8-469a-9ae1-f601c9371ffd']
-
- # what OpenStack is assumed to respond (patch OpenStack's return value)
- dict_from_neutron = {'port_pair_group': {
- 'id': '3d7ddc13-923c-4332-971e-708ed82902ce',
- 'name': name,
- 'description': '',
- 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
- 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
- 'port_pairs': instances,
- 'group_id': 1,
- 'port_pair_group_parameters': {
- "lb_fields": [],
- "ppg_n_tuple_mapping": {
- "ingress_n_tuple": {},
- "egress_n_tuple": {}
- }}
- }}
- create_port_pair_group.return_value = dict_from_neutron
-
- # what the VIM connector is expected to
- # send to OpenStack based on the input
- dict_to_neutron = {'port_pair_group': {
- 'name': name,
- 'port_pairs': ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd',
- '12ba215e-3987-4892-bd3a-d0fd91eecf98',
- 'e25a7c79-14c8-469a-9ae1-f601c9371ffd']
- }}
-
- # call the VIM connector
- result = self.vimconn.new_sf(name, instances)
-
- # assert that the VIM connector made the expected call to OpenStack
- create_port_pair_group.assert_called_with(dict_to_neutron)
- # assert that the VIM connector had the expected result / return value
- self.assertEqual(result, dict_from_neutron['port_pair_group']['id'])
-
- def _test_new_sfp(self, create_port_chain, sfc_encap, spi):
- # input to VIM connector
- name = 'osm_sfp'
- classifications = ['2bd2a2e5-c5fd-4eac-a297-d5e255c35c19',
- '00f23389-bdfa-43c2-8b16-5815f2582fa8']
- sfs = ['2314daec-c262-414a-86e3-69bb6fa5bc16',
- 'd8bfdb5d-195e-4f34-81aa-6135705317df']
-
- # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
- correlation = 'mpls'
- chain_id = 33
- if sfc_encap is not None:
- if not sfc_encap:
- correlation = None
- if spi:
- chain_id = spi
-
- # what OpenStack is assumed to respond (patch OpenStack's return value)
- dict_from_neutron = {'port_chain': {
- 'id': '5bc05721-079b-4b6e-a235-47cac331cbb6',
- 'name': name,
- 'description': '',
- 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
- 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
- 'chain_id': chain_id,
- 'flow_classifiers': classifications,
- 'port_pair_groups': sfs,
- 'chain_parameters': {'correlation': correlation}
- }}
- create_port_chain.return_value = dict_from_neutron
-
- # what the VIM connector is expected to
- # send to OpenStack based on the input
- dict_to_neutron = {'port_chain': {
- 'name': name,
- 'flow_classifiers': ['2bd2a2e5-c5fd-4eac-a297-d5e255c35c19',
- '00f23389-bdfa-43c2-8b16-5815f2582fa8'],
- 'port_pair_groups': ['2314daec-c262-414a-86e3-69bb6fa5bc16',
- 'd8bfdb5d-195e-4f34-81aa-6135705317df'],
- 'chain_parameters': {'correlation': correlation}
- }}
- if spi:
- dict_to_neutron['port_chain']['chain_id'] = spi
-
- # call the VIM connector
- if sfc_encap is None:
- if spi is None:
- result = self.vimconn.new_sfp(name, classifications, sfs)
- else:
- result = self.vimconn.new_sfp(name, classifications, sfs,
- spi=spi)
- else:
- if spi is None:
- result = self.vimconn.new_sfp(name, classifications, sfs,
- sfc_encap)
- else:
- result = self.vimconn.new_sfp(name, classifications, sfs,
- sfc_encap, spi)
-
- # assert that the VIM connector made the expected call to OpenStack
- create_port_chain.assert_called_with(dict_to_neutron)
- # assert that the VIM connector had the expected result / return value
- self.assertEqual(result, dict_from_neutron['port_chain']['id'])
-
- def _test_new_classification(self, create_flow_classifier, ctype):
- # input to VIM connector
- name = 'osm_classification'
- definition = {'ethertype': 'IPv4',
- 'logical_source_port':
- 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
- 'protocol': 'tcp',
- 'source_ip_prefix': '192.168.2.0/24',
- 'source_port_range_max': 99,
- 'source_port_range_min': 50}
-
- # what OpenStack is assumed to respond (patch OpenStack's return value)
- dict_from_neutron = {'flow_classifier': copy.copy(definition)}
- dict_from_neutron['flow_classifier'][
- 'id'] = '7735ec2c-fddf-4130-9712-32ed2ab6a372'
- dict_from_neutron['flow_classifier']['name'] = name
- dict_from_neutron['flow_classifier']['description'] = ''
- dict_from_neutron['flow_classifier'][
- 'tenant_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c'
- dict_from_neutron['flow_classifier'][
- 'project_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c'
- create_flow_classifier.return_value = dict_from_neutron
-
- # what the VIM connector is expected to
- # send to OpenStack based on the input
- dict_to_neutron = {'flow_classifier': copy.copy(definition)}
- dict_to_neutron['flow_classifier']['name'] = 'osm_classification'
-
- # call the VIM connector
- result = self.vimconn.new_classification(name, ctype, definition)
-
- # assert that the VIM connector made the expected call to OpenStack
- create_flow_classifier.assert_called_with(dict_to_neutron)
- # assert that the VIM connector had the expected result / return value
- self.assertEqual(result, dict_from_neutron['flow_classifier']['id'])
-
- @mock.patch.object(Client, 'create_flow_classifier')
- def test_new_classification(self, create_flow_classifier):
- self._test_new_classification(create_flow_classifier,
- 'legacy_flow_classifier')
-
- @mock.patch.object(Client, 'create_flow_classifier')
- def test_new_classification_unsupported_type(self, create_flow_classifier):
- self.assertRaises(vimconn.vimconnNotSupportedException,
- self._test_new_classification,
- create_flow_classifier, 'h265')
-
- @mock.patch.object(Client, 'create_port_pair')
- def test_new_sfi_with_sfc_encap(self, create_port_pair):
- self._test_new_sfi(create_port_pair, True)
-
- @mock.patch.object(Client, 'create_port_pair')
- def test_new_sfi_without_sfc_encap(self, create_port_pair):
- self._test_new_sfi(create_port_pair, False)
-
- @mock.patch.object(Client, 'create_port_pair')
- def test_new_sfi_default_sfc_encap(self, create_port_pair):
- self._test_new_sfi(create_port_pair, None)
-
- @mock.patch.object(Client, 'create_port_pair')
- def test_new_sfi_bad_ingress_ports(self, create_port_pair):
- ingress_ports = ['5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'a0273f64-82c9-11e7-b08f-6328e53f0fa7']
- self.assertRaises(vimconn.vimconnNotSupportedException,
- self._test_new_sfi,
- create_port_pair, True, ingress_ports=ingress_ports)
- ingress_ports = []
- self.assertRaises(vimconn.vimconnNotSupportedException,
- self._test_new_sfi,
- create_port_pair, True, ingress_ports=ingress_ports)
-
- @mock.patch.object(Client, 'create_port_pair')
- def test_new_sfi_bad_egress_ports(self, create_port_pair):
- egress_ports = ['230cdf1b-de37-4891-bc07-f9010cf1f967',
- 'b41228fe-82c9-11e7-9b44-17504174320b']
- self.assertRaises(vimconn.vimconnNotSupportedException,
- self._test_new_sfi,
- create_port_pair, True, egress_ports=egress_ports)
- egress_ports = []
- self.assertRaises(vimconn.vimconnNotSupportedException,
- self._test_new_sfi,
- create_port_pair, True, egress_ports=egress_ports)
-
- @mock.patch.object(vimconnector, 'get_sfi')
- @mock.patch.object(Client, 'create_port_pair_group')
- def test_new_sf(self, create_port_pair_group, get_sfi):
- get_sfi.return_value = {'sfc_encap': 'mpls'}
- self._test_new_sf(create_port_pair_group)
-
- @mock.patch.object(vimconnector, 'get_sfi')
- @mock.patch.object(Client, 'create_port_pair_group')
- def test_new_sf_inconsistent_sfc_encap(self, create_port_pair_group,
- get_sfi):
- get_sfi.return_value = {'sfc_encap': 'nsh'}
- self.assertRaises(vimconn.vimconnNotSupportedException,
- self._test_new_sf, create_port_pair_group)
-
- @mock.patch.object(Client, 'create_port_chain')
- def test_new_sfp_with_sfc_encap(self, create_port_chain):
- self._test_new_sfp(create_port_chain, True, None)
-
- @mock.patch.object(Client, 'create_port_chain')
- def test_new_sfp_without_sfc_encap(self, create_port_chain):
- self.assertRaises(vimconn.vimconnNotSupportedException,
- self._test_new_sfp,
- create_port_chain, False, None)
- self.assertRaises(vimconn.vimconnNotSupportedException,
- self._test_new_sfp,
- create_port_chain, False, 25)
-
- @mock.patch.object(Client, 'create_port_chain')
- def test_new_sfp_default_sfc_encap(self, create_port_chain):
- self._test_new_sfp(create_port_chain, None, None)
-
- @mock.patch.object(Client, 'create_port_chain')
- def test_new_sfp_with_sfc_encap_spi(self, create_port_chain):
- self._test_new_sfp(create_port_chain, True, 25)
-
- @mock.patch.object(Client, 'create_port_chain')
- def test_new_sfp_default_sfc_encap_spi(self, create_port_chain):
- self._test_new_sfp(create_port_chain, None, 25)
-
- @mock.patch.object(Client, 'list_flow_classifier')
- def test_get_classification_list(self, list_flow_classifier):
- # what OpenStack is assumed to return to the VIM connector
- list_flow_classifier.return_value = {'flow_classifiers': [
- {'source_port_range_min': 2000,
- 'destination_ip_prefix': '192.168.3.0/24',
- 'protocol': 'udp',
- 'description': '',
- 'ethertype': 'IPv4',
- 'l7_parameters': {},
- 'source_port_range_max': 2000,
- 'destination_port_range_min': 3000,
- 'source_ip_prefix': '192.168.2.0/24',
- 'logical_destination_port': None,
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'destination_port_range_max': None,
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
- 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
- 'name': 'fc1'}]}
-
- # call the VIM connector
- filter_dict = {'protocol': 'tcp', 'ethertype': 'IPv4'}
- result = self.vimconn.get_classification_list(filter_dict.copy())
-
- # assert that VIM connector called OpenStack with the expected filter
- list_flow_classifier.assert_called_with(**filter_dict)
- # assert that the VIM connector successfully
- # translated and returned the OpenStack result
- self.assertEqual(result, [
- {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
- 'name': 'fc1',
- 'description': '',
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'ctype': 'legacy_flow_classifier',
- 'definition': {
- 'source_port_range_min': 2000,
- 'destination_ip_prefix': '192.168.3.0/24',
- 'protocol': 'udp',
- 'ethertype': 'IPv4',
- 'l7_parameters': {},
- 'source_port_range_max': 2000,
- 'destination_port_range_min': 3000,
- 'source_ip_prefix': '192.168.2.0/24',
- 'logical_destination_port': None,
- 'destination_port_range_max': None,
- 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'}
- }])
-
- def _test_get_sfi_list(self, list_port_pair, correlation, sfc_encap):
- # what OpenStack is assumed to return to the VIM connector
- list_port_pair.return_value = {'port_pairs': [
- {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'service_function_parameters': {'correlation': correlation},
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
- 'name': 'osm_sfi'}]}
-
- # call the VIM connector
- filter_dict = {'name': 'osm_sfi', 'description': ''}
- result = self.vimconn.get_sfi_list(filter_dict.copy())
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_pair.assert_called_with(**filter_dict)
- # assert that the VIM connector successfully
- # translated and returned the OpenStack result
- self.assertEqual(result, [
- {'ingress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'egress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
- 'sfc_encap': sfc_encap,
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
- 'name': 'osm_sfi'}])
-
- @mock.patch.object(Client, 'list_port_pair')
- def test_get_sfi_list_with_sfc_encap(self, list_port_pair):
- self._test_get_sfi_list(list_port_pair, 'nsh', True)
-
- @mock.patch.object(Client, 'list_port_pair')
- def test_get_sfi_list_without_sfc_encap(self, list_port_pair):
- self._test_get_sfi_list(list_port_pair, None, False)
-
- @mock.patch.object(Client, 'list_port_pair_group')
- def test_get_sf_list(self, list_port_pair_group):
- # what OpenStack is assumed to return to the VIM connector
- list_port_pair_group.return_value = {'port_pair_groups': [
- {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
- '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'port_pair_group_parameters': {},
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
- 'name': 'osm_sf'}]}
-
- # call the VIM connector
- filter_dict = {'name': 'osm_sf', 'description': ''}
- result = self.vimconn.get_sf_list(filter_dict.copy())
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_pair_group.assert_called_with(**filter_dict)
- # assert that the VIM connector successfully
- # translated and returned the OpenStack result
- self.assertEqual(result, [
- {'instances': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
- '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
- 'name': 'osm_sf'}])
-
- def _test_get_sfp_list(self, list_port_chain, correlation, sfc_encap):
- # what OpenStack is assumed to return to the VIM connector
- list_port_chain.return_value = {'port_chains': [
- {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25',
- '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'],
- 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e',
- '1387ab44-82d7-11e7-9bb0-476337183905'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'chain_parameters': {'correlation': correlation},
- 'chain_id': 40,
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
- 'name': 'osm_sfp'}]}
-
- # call the VIM connector
- filter_dict = {'name': 'osm_sfp', 'description': ''}
- result = self.vimconn.get_sfp_list(filter_dict.copy())
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_chain.assert_called_with(**filter_dict)
- # assert that the VIM connector successfully
- # translated and returned the OpenStack result
- self.assertEqual(result, [
- {'service_functions': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25',
- '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'],
- 'classifications': ['1333c2f4-82d7-11e7-a5df-9327f33d104e',
- '1387ab44-82d7-11e7-9bb0-476337183905'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'sfc_encap': sfc_encap,
- 'spi': 40,
- 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
- 'name': 'osm_sfp'}])
-
- @mock.patch.object(Client, 'list_port_chain')
- def test_get_sfp_list_with_sfc_encap(self, list_port_chain):
- self._test_get_sfp_list(list_port_chain, 'nsh', True)
-
- @mock.patch.object(Client, 'list_port_chain')
- def test_get_sfp_list_without_sfc_encap(self, list_port_chain):
- self._test_get_sfp_list(list_port_chain, None, False)
-
- @mock.patch.object(Client, 'list_flow_classifier')
- def test_get_classification(self, list_flow_classifier):
- # what OpenStack is assumed to return to the VIM connector
- list_flow_classifier.return_value = {'flow_classifiers': [
- {'source_port_range_min': 2000,
- 'destination_ip_prefix': '192.168.3.0/24',
- 'protocol': 'udp',
- 'description': '',
- 'ethertype': 'IPv4',
- 'l7_parameters': {},
- 'source_port_range_max': 2000,
- 'destination_port_range_min': 3000,
- 'source_ip_prefix': '192.168.2.0/24',
- 'logical_destination_port': None,
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'destination_port_range_max': None,
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
- 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
- 'name': 'fc1'}
- ]}
-
- # call the VIM connector
- result = self.vimconn.get_classification(
- '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d')
-
- # assert that VIM connector called OpenStack with the expected filter
- list_flow_classifier.assert_called_with(
- id='22198366-d4e8-4d6b-b4d2-637d5d6cbb7d')
- # assert that VIM connector successfully returned the OpenStack result
- self.assertEqual(result,
- {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
- 'name': 'fc1',
- 'description': '',
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'ctype': 'legacy_flow_classifier',
- 'definition': {
- 'source_port_range_min': 2000,
- 'destination_ip_prefix': '192.168.3.0/24',
- 'protocol': 'udp',
- 'ethertype': 'IPv4',
- 'l7_parameters': {},
- 'source_port_range_max': 2000,
- 'destination_port_range_min': 3000,
- 'source_ip_prefix': '192.168.2.0/24',
- 'logical_destination_port': None,
- 'destination_port_range_max': None,
- 'logical_source_port':
- 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'}
- })
-
- @mock.patch.object(Client, 'list_flow_classifier')
- def test_get_classification_many_results(self, list_flow_classifier):
- # what OpenStack is assumed to return to the VIM connector
- list_flow_classifier.return_value = {'flow_classifiers': [
- {'source_port_range_min': 2000,
- 'destination_ip_prefix': '192.168.3.0/24',
- 'protocol': 'udp',
- 'description': '',
- 'ethertype': 'IPv4',
- 'l7_parameters': {},
- 'source_port_range_max': 2000,
- 'destination_port_range_min': 3000,
- 'source_ip_prefix': '192.168.2.0/24',
- 'logical_destination_port': None,
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'destination_port_range_max': None,
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
- 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
- 'name': 'fc1'},
- {'source_port_range_min': 1000,
- 'destination_ip_prefix': '192.168.3.0/24',
- 'protocol': 'udp',
- 'description': '',
- 'ethertype': 'IPv4',
- 'l7_parameters': {},
- 'source_port_range_max': 1000,
- 'destination_port_range_min': 3000,
- 'source_ip_prefix': '192.168.2.0/24',
- 'logical_destination_port': None,
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'destination_port_range_max': None,
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
- 'id': '3196bafc-82dd-11e7-a205-9bf6c14b0721',
- 'name': 'fc2'}
- ]}
-
- # call the VIM connector
- self.assertRaises(vimconn.vimconnConflictException,
- self.vimconn.get_classification,
- '3196bafc-82dd-11e7-a205-9bf6c14b0721')
-
- # assert the VIM connector called OpenStack with the expected filter
- list_flow_classifier.assert_called_with(
- id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
-
- @mock.patch.object(Client, 'list_flow_classifier')
- def test_get_classification_no_results(self, list_flow_classifier):
- # what OpenStack is assumed to return to the VIM connector
- list_flow_classifier.return_value = {'flow_classifiers': []}
-
- # call the VIM connector
- self.assertRaises(vimconn.vimconnNotFoundException,
- self.vimconn.get_classification,
- '3196bafc-82dd-11e7-a205-9bf6c14b0721')
-
- # assert the VIM connector called OpenStack with the expected filter
- list_flow_classifier.assert_called_with(
- id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
-
- @mock.patch.object(Client, 'list_port_pair')
- def test_get_sfi(self, list_port_pair):
- # what OpenStack is assumed to return to the VIM connector
- list_port_pair.return_value = {'port_pairs': [
- {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'service_function_parameters': {'correlation': 'nsh'},
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
- 'name': 'osm_sfi1'},
- ]}
-
- # call the VIM connector
- result = self.vimconn.get_sfi('c121ebdd-7f2d-4213-b933-3325298a6966')
-
- # assert the VIM connector called OpenStack with the expected filter
- list_port_pair.assert_called_with(
- id='c121ebdd-7f2d-4213-b933-3325298a6966')
- # assert the VIM connector successfully returned the OpenStack result
- self.assertEqual(result,
- {'ingress_ports': [
- '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
- 'egress_ports': [
- '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
- 'sfc_encap': True,
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
- 'name': 'osm_sfi1'})
-
- @mock.patch.object(Client, 'list_port_pair')
- def test_get_sfi_many_results(self, list_port_pair):
- # what OpenStack is assumed to return to the VIM connector
- list_port_pair.return_value = {'port_pairs': [
- {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'service_function_parameters': {'correlation': 'nsh'},
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
- 'name': 'osm_sfi1'},
- {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
- 'service_function_parameters': {'correlation': 'nsh'},
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'c0436d92-82db-11e7-8f9c-5fa535f1261f',
- 'name': 'osm_sfi2'}
- ]}
-
- # call the VIM connector
- self.assertRaises(vimconn.vimconnConflictException,
- self.vimconn.get_sfi,
- 'c0436d92-82db-11e7-8f9c-5fa535f1261f')
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_pair.assert_called_with(
- id='c0436d92-82db-11e7-8f9c-5fa535f1261f')
-
- @mock.patch.object(Client, 'list_port_pair')
- def test_get_sfi_no_results(self, list_port_pair):
- # what OpenStack is assumed to return to the VIM connector
- list_port_pair.return_value = {'port_pairs': []}
-
- # call the VIM connector
- self.assertRaises(vimconn.vimconnNotFoundException,
- self.vimconn.get_sfi,
- 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_pair.assert_called_with(
- id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
-
- @mock.patch.object(Client, 'list_port_pair_group')
- def test_get_sf(self, list_port_pair_group):
- # what OpenStack is assumed to return to the VIM connector
- list_port_pair_group.return_value = {'port_pair_groups': [
- {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'port_pair_group_parameters': {},
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
- 'name': 'osm_sf1'}
- ]}
-
- # call the VIM connector
- result = self.vimconn.get_sf('b22892fc-82d9-11e7-ae85-0fea6a3b3757')
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_pair_group.assert_called_with(
- id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
- # assert that VIM connector successfully returned the OpenStack result
- self.assertEqual(result,
- {'instances': [
- '08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
- 'name': 'osm_sf1'})
-
- @mock.patch.object(Client, 'list_port_pair_group')
- def test_get_sf_many_results(self, list_port_pair_group):
- # what OpenStack is assumed to return to the VIM connector
- list_port_pair_group.return_value = {'port_pair_groups': [
- {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'port_pair_group_parameters': {},
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
- 'name': 'osm_sf1'},
- {'port_pairs': ['0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'port_pair_group_parameters': {},
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': 'b22892fc-82d9-11e7-ae85-0fea6a3b3757',
- 'name': 'osm_sf2'}
- ]}
-
- # call the VIM connector
- self.assertRaises(vimconn.vimconnConflictException,
- self.vimconn.get_sf,
- 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_pair_group.assert_called_with(
- id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
-
- @mock.patch.object(Client, 'list_port_pair_group')
- def test_get_sf_no_results(self, list_port_pair_group):
- # what OpenStack is assumed to return to the VIM connector
- list_port_pair_group.return_value = {'port_pair_groups': []}
-
- # call the VIM connector
- self.assertRaises(vimconn.vimconnNotFoundException,
- self.vimconn.get_sf,
- 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_pair_group.assert_called_with(
- id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
-
- @mock.patch.object(Client, 'list_port_chain')
- def test_get_sfp(self, list_port_chain):
- # what OpenStack is assumed to return to the VIM connector
- list_port_chain.return_value = {'port_chains': [
- {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
- 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'chain_parameters': {'correlation': 'nsh'},
- 'chain_id': 40,
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
- 'name': 'osm_sfp1'}]}
-
- # call the VIM connector
- result = self.vimconn.get_sfp('821bc9be-82d7-11e7-8ce3-23a08a27ab47')
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_chain.assert_called_with(
- id='821bc9be-82d7-11e7-8ce3-23a08a27ab47')
- # assert that VIM connector successfully returned the OpenStack result
- self.assertEqual(result,
- {'service_functions': [
- '7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
- 'classifications': [
- '1333c2f4-82d7-11e7-a5df-9327f33d104e'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'sfc_encap': True,
- 'spi': 40,
- 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
- 'name': 'osm_sfp1'})
-
- @mock.patch.object(Client, 'list_port_chain')
- def test_get_sfp_many_results(self, list_port_chain):
- # what OpenStack is assumed to return to the VIM connector
- list_port_chain.return_value = {'port_chains': [
- {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
- 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'chain_parameters': {'correlation': 'nsh'},
- 'chain_id': 40,
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
- 'name': 'osm_sfp1'},
- {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
- 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
- 'description': '',
- 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'chain_parameters': {'correlation': 'nsh'},
- 'chain_id': 50,
- 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
- 'id': '5d002f38-82de-11e7-a770-f303f11ce66a',
- 'name': 'osm_sfp2'}
- ]}
-
- # call the VIM connector
- self.assertRaises(vimconn.vimconnConflictException,
- self.vimconn.get_sfp,
- '5d002f38-82de-11e7-a770-f303f11ce66a')
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_chain.assert_called_with(
- id='5d002f38-82de-11e7-a770-f303f11ce66a')
-
- @mock.patch.object(Client, 'list_port_chain')
- def test_get_sfp_no_results(self, list_port_chain):
- # what OpenStack is assumed to return to the VIM connector
- list_port_chain.return_value = {'port_chains': []}
-
- # call the VIM connector
- self.assertRaises(vimconn.vimconnNotFoundException,
- self.vimconn.get_sfp,
- '5d002f38-82de-11e7-a770-f303f11ce66a')
-
- # assert that VIM connector called OpenStack with the expected filter
- list_port_chain.assert_called_with(
- id='5d002f38-82de-11e7-a770-f303f11ce66a')
-
- @mock.patch.object(Client, 'delete_flow_classifier')
- def test_delete_classification(self, delete_flow_classifier):
- result = self.vimconn.delete_classification(
- '638f957c-82df-11e7-b7c8-132706021464')
- delete_flow_classifier.assert_called_with(
- '638f957c-82df-11e7-b7c8-132706021464')
- self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
-
- @mock.patch.object(Client, 'delete_port_pair')
- def test_delete_sfi(self, delete_port_pair):
- result = self.vimconn.delete_sfi(
- '638f957c-82df-11e7-b7c8-132706021464')
- delete_port_pair.assert_called_with(
- '638f957c-82df-11e7-b7c8-132706021464')
- self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
-
- @mock.patch.object(Client, 'delete_port_pair_group')
- def test_delete_sf(self, delete_port_pair_group):
- result = self.vimconn.delete_sf('638f957c-82df-11e7-b7c8-132706021464')
- delete_port_pair_group.assert_called_with(
- '638f957c-82df-11e7-b7c8-132706021464')
- self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
-
- @mock.patch.object(Client, 'delete_port_chain')
- def test_delete_sfp(self, delete_port_chain):
- result = self.vimconn.delete_sfp(
- '638f957c-82df-11e7-b7c8-132706021464')
- delete_port_chain.assert_called_with(
- '638f957c-82df-11e7-b7c8-132706021464')
- self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
-
-
-if __name__ == '__main__':
- unittest.main()
--- /dev/null
+# -*- coding: utf-8 -*-
+
+##
+# Copyright 2017 Intel Corporation.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact with: nfvlabs@tid.es
+##
+
+"""
+This module contains unit tests for the OpenStack VIM connector
+Run this directly with python2 or python3.
+"""
+
+import copy
+import unittest
+
+import mock
+from neutronclient.v2_0.client import Client
+
+from osm_ro import vimconn
+from osm_ro.vimconn_openstack import vimconnector
+
+
+__author__ = "Igor D.C."
+__date__ = "$23-aug-2017 23:59:59$"
+
+
+class TestSfcOperations(unittest.TestCase):
+ def setUp(self):
+ # instantiate dummy VIM connector so we can test it
+ self.vimconn = vimconnector(
+ '123', 'openstackvim', '456', '789', 'http://dummy.url', None,
+ 'user', 'pass')
+
+ def _test_new_sfi(self, create_port_pair, sfc_encap,
+ ingress_ports=['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
+ egress_ports=['230cdf1b-de37-4891-bc07-f9010cf1f967']):
+ # input to VIM connector
+ name = 'osm_sfi'
+ # + ingress_ports
+ # + egress_ports
+ # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
+ correlation = 'mpls'
+ if sfc_encap is not None:
+ if not sfc_encap:
+ correlation = None
+
+ # what OpenStack is assumed to respond (patch OpenStack's return value)
+ dict_from_neutron = {'port_pair': {
+ 'id': '3d7ddc13-923c-4332-971e-708ed82902ce',
+ 'name': name,
+ 'description': '',
+ 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
+ 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
+ 'ingress': ingress_ports[0] if len(ingress_ports) else None,
+ 'egress': egress_ports[0] if len(egress_ports) else None,
+ 'service_function_parameters': {'correlation': correlation}
+ }}
+ create_port_pair.return_value = dict_from_neutron
+
+ # what the VIM connector is expected to
+ # send to OpenStack based on the input
+ dict_to_neutron = {'port_pair': {
+ 'name': name,
+ 'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'egress': '230cdf1b-de37-4891-bc07-f9010cf1f967',
+ 'service_function_parameters': {'correlation': correlation}
+ }}
+
+ # call the VIM connector
+ if sfc_encap is None:
+ result = self.vimconn.new_sfi(name, ingress_ports, egress_ports)
+ else:
+ result = self.vimconn.new_sfi(name, ingress_ports, egress_ports,
+ sfc_encap)
+
+ # assert that the VIM connector made the expected call to OpenStack
+ create_port_pair.assert_called_with(dict_to_neutron)
+ # assert that the VIM connector had the expected result / return value
+ self.assertEqual(result, dict_from_neutron['port_pair']['id'])
+
+ def _test_new_sf(self, create_port_pair_group):
+ # input to VIM connector
+ name = 'osm_sf'
+ instances = ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd',
+ '12ba215e-3987-4892-bd3a-d0fd91eecf98',
+ 'e25a7c79-14c8-469a-9ae1-f601c9371ffd']
+
+ # what OpenStack is assumed to respond (patch OpenStack's return value)
+ dict_from_neutron = {'port_pair_group': {
+ 'id': '3d7ddc13-923c-4332-971e-708ed82902ce',
+ 'name': name,
+ 'description': '',
+ 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
+ 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
+ 'port_pairs': instances,
+ 'group_id': 1,
+ 'port_pair_group_parameters': {
+ "lb_fields": [],
+ "ppg_n_tuple_mapping": {
+ "ingress_n_tuple": {},
+ "egress_n_tuple": {}
+ }}
+ }}
+ create_port_pair_group.return_value = dict_from_neutron
+
+ # what the VIM connector is expected to
+ # send to OpenStack based on the input
+ dict_to_neutron = {'port_pair_group': {
+ 'name': name,
+ 'port_pairs': ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd',
+ '12ba215e-3987-4892-bd3a-d0fd91eecf98',
+ 'e25a7c79-14c8-469a-9ae1-f601c9371ffd']
+ }}
+
+ # call the VIM connector
+ result = self.vimconn.new_sf(name, instances)
+
+ # assert that the VIM connector made the expected call to OpenStack
+ create_port_pair_group.assert_called_with(dict_to_neutron)
+ # assert that the VIM connector had the expected result / return value
+ self.assertEqual(result, dict_from_neutron['port_pair_group']['id'])
+
+ def _test_new_sfp(self, create_port_chain, sfc_encap, spi):
+ # input to VIM connector
+ name = 'osm_sfp'
+ classifications = ['2bd2a2e5-c5fd-4eac-a297-d5e255c35c19',
+ '00f23389-bdfa-43c2-8b16-5815f2582fa8']
+ sfs = ['2314daec-c262-414a-86e3-69bb6fa5bc16',
+ 'd8bfdb5d-195e-4f34-81aa-6135705317df']
+
+ # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
+ correlation = 'mpls'
+ chain_id = 33
+ if sfc_encap is not None:
+ if not sfc_encap:
+ correlation = None
+ if spi:
+ chain_id = spi
+
+ # what OpenStack is assumed to respond (patch OpenStack's return value)
+ dict_from_neutron = {'port_chain': {
+ 'id': '5bc05721-079b-4b6e-a235-47cac331cbb6',
+ 'name': name,
+ 'description': '',
+ 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
+ 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
+ 'chain_id': chain_id,
+ 'flow_classifiers': classifications,
+ 'port_pair_groups': sfs,
+ 'chain_parameters': {'correlation': correlation}
+ }}
+ create_port_chain.return_value = dict_from_neutron
+
+ # what the VIM connector is expected to
+ # send to OpenStack based on the input
+ dict_to_neutron = {'port_chain': {
+ 'name': name,
+ 'flow_classifiers': ['2bd2a2e5-c5fd-4eac-a297-d5e255c35c19',
+ '00f23389-bdfa-43c2-8b16-5815f2582fa8'],
+ 'port_pair_groups': ['2314daec-c262-414a-86e3-69bb6fa5bc16',
+ 'd8bfdb5d-195e-4f34-81aa-6135705317df'],
+ 'chain_parameters': {'correlation': correlation}
+ }}
+ if spi:
+ dict_to_neutron['port_chain']['chain_id'] = spi
+
+ # call the VIM connector
+ if sfc_encap is None:
+ if spi is None:
+ result = self.vimconn.new_sfp(name, classifications, sfs)
+ else:
+ result = self.vimconn.new_sfp(name, classifications, sfs,
+ spi=spi)
+ else:
+ if spi is None:
+ result = self.vimconn.new_sfp(name, classifications, sfs,
+ sfc_encap)
+ else:
+ result = self.vimconn.new_sfp(name, classifications, sfs,
+ sfc_encap, spi)
+
+ # assert that the VIM connector made the expected call to OpenStack
+ create_port_chain.assert_called_with(dict_to_neutron)
+ # assert that the VIM connector had the expected result / return value
+ self.assertEqual(result, dict_from_neutron['port_chain']['id'])
+
+ def _test_new_classification(self, create_flow_classifier, ctype):
+ # input to VIM connector
+ name = 'osm_classification'
+ definition = {'ethertype': 'IPv4',
+ 'logical_source_port':
+ 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
+ 'protocol': 'tcp',
+ 'source_ip_prefix': '192.168.2.0/24',
+ 'source_port_range_max': 99,
+ 'source_port_range_min': 50}
+
+ # what OpenStack is assumed to respond (patch OpenStack's return value)
+ dict_from_neutron = {'flow_classifier': copy.copy(definition)}
+ dict_from_neutron['flow_classifier'][
+ 'id'] = '7735ec2c-fddf-4130-9712-32ed2ab6a372'
+ dict_from_neutron['flow_classifier']['name'] = name
+ dict_from_neutron['flow_classifier']['description'] = ''
+ dict_from_neutron['flow_classifier'][
+ 'tenant_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c'
+ dict_from_neutron['flow_classifier'][
+ 'project_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c'
+ create_flow_classifier.return_value = dict_from_neutron
+
+ # what the VIM connector is expected to
+ # send to OpenStack based on the input
+ dict_to_neutron = {'flow_classifier': copy.copy(definition)}
+ dict_to_neutron['flow_classifier']['name'] = 'osm_classification'
+
+ # call the VIM connector
+ result = self.vimconn.new_classification(name, ctype, definition)
+
+ # assert that the VIM connector made the expected call to OpenStack
+ create_flow_classifier.assert_called_with(dict_to_neutron)
+ # assert that the VIM connector had the expected result / return value
+ self.assertEqual(result, dict_from_neutron['flow_classifier']['id'])
+
+ @mock.patch.object(Client, 'create_flow_classifier')
+ def test_new_classification(self, create_flow_classifier):
+ self._test_new_classification(create_flow_classifier,
+ 'legacy_flow_classifier')
+
+ @mock.patch.object(Client, 'create_flow_classifier')
+ def test_new_classification_unsupported_type(self, create_flow_classifier):
+ self.assertRaises(vimconn.vimconnNotSupportedException,
+ self._test_new_classification,
+ create_flow_classifier, 'h265')
+
+ @mock.patch.object(Client, 'create_port_pair')
+ def test_new_sfi_with_sfc_encap(self, create_port_pair):
+ self._test_new_sfi(create_port_pair, True)
+
+ @mock.patch.object(Client, 'create_port_pair')
+ def test_new_sfi_without_sfc_encap(self, create_port_pair):
+ self._test_new_sfi(create_port_pair, False)
+
+ @mock.patch.object(Client, 'create_port_pair')
+ def test_new_sfi_default_sfc_encap(self, create_port_pair):
+ self._test_new_sfi(create_port_pair, None)
+
+ @mock.patch.object(Client, 'create_port_pair')
+ def test_new_sfi_bad_ingress_ports(self, create_port_pair):
+ ingress_ports = ['5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'a0273f64-82c9-11e7-b08f-6328e53f0fa7']
+ self.assertRaises(vimconn.vimconnNotSupportedException,
+ self._test_new_sfi,
+ create_port_pair, True, ingress_ports=ingress_ports)
+ ingress_ports = []
+ self.assertRaises(vimconn.vimconnNotSupportedException,
+ self._test_new_sfi,
+ create_port_pair, True, ingress_ports=ingress_ports)
+
+ @mock.patch.object(Client, 'create_port_pair')
+ def test_new_sfi_bad_egress_ports(self, create_port_pair):
+ egress_ports = ['230cdf1b-de37-4891-bc07-f9010cf1f967',
+ 'b41228fe-82c9-11e7-9b44-17504174320b']
+ self.assertRaises(vimconn.vimconnNotSupportedException,
+ self._test_new_sfi,
+ create_port_pair, True, egress_ports=egress_ports)
+ egress_ports = []
+ self.assertRaises(vimconn.vimconnNotSupportedException,
+ self._test_new_sfi,
+ create_port_pair, True, egress_ports=egress_ports)
+
+ @mock.patch.object(vimconnector, 'get_sfi')
+ @mock.patch.object(Client, 'create_port_pair_group')
+ def test_new_sf(self, create_port_pair_group, get_sfi):
+ get_sfi.return_value = {'sfc_encap': 'mpls'}
+ self._test_new_sf(create_port_pair_group)
+
+ @mock.patch.object(vimconnector, 'get_sfi')
+ @mock.patch.object(Client, 'create_port_pair_group')
+ def test_new_sf_inconsistent_sfc_encap(self, create_port_pair_group,
+ get_sfi):
+ get_sfi.return_value = {'sfc_encap': 'nsh'}
+ self.assertRaises(vimconn.vimconnNotSupportedException,
+ self._test_new_sf, create_port_pair_group)
+
+ @mock.patch.object(Client, 'create_port_chain')
+ def test_new_sfp_with_sfc_encap(self, create_port_chain):
+ self._test_new_sfp(create_port_chain, True, None)
+
+ @mock.patch.object(Client, 'create_port_chain')
+ def test_new_sfp_without_sfc_encap(self, create_port_chain):
+ self.assertRaises(vimconn.vimconnNotSupportedException,
+ self._test_new_sfp,
+ create_port_chain, False, None)
+ self.assertRaises(vimconn.vimconnNotSupportedException,
+ self._test_new_sfp,
+ create_port_chain, False, 25)
+
+ @mock.patch.object(Client, 'create_port_chain')
+ def test_new_sfp_default_sfc_encap(self, create_port_chain):
+ self._test_new_sfp(create_port_chain, None, None)
+
+ @mock.patch.object(Client, 'create_port_chain')
+ def test_new_sfp_with_sfc_encap_spi(self, create_port_chain):
+ self._test_new_sfp(create_port_chain, True, 25)
+
+ @mock.patch.object(Client, 'create_port_chain')
+ def test_new_sfp_default_sfc_encap_spi(self, create_port_chain):
+ self._test_new_sfp(create_port_chain, None, 25)
+
+ @mock.patch.object(Client, 'list_flow_classifier')
+ def test_get_classification_list(self, list_flow_classifier):
+ # what OpenStack is assumed to return to the VIM connector
+ list_flow_classifier.return_value = {'flow_classifiers': [
+ {'source_port_range_min': 2000,
+ 'destination_ip_prefix': '192.168.3.0/24',
+ 'protocol': 'udp',
+ 'description': '',
+ 'ethertype': 'IPv4',
+ 'l7_parameters': {},
+ 'source_port_range_max': 2000,
+ 'destination_port_range_min': 3000,
+ 'source_ip_prefix': '192.168.2.0/24',
+ 'logical_destination_port': None,
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'destination_port_range_max': None,
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
+ 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
+ 'name': 'fc1'}]}
+
+ # call the VIM connector
+ filter_dict = {'protocol': 'tcp', 'ethertype': 'IPv4'}
+ result = self.vimconn.get_classification_list(filter_dict.copy())
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_flow_classifier.assert_called_with(**filter_dict)
+ # assert that the VIM connector successfully
+ # translated and returned the OpenStack result
+ self.assertEqual(result, [
+ {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
+ 'name': 'fc1',
+ 'description': '',
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'ctype': 'legacy_flow_classifier',
+ 'definition': {
+ 'source_port_range_min': 2000,
+ 'destination_ip_prefix': '192.168.3.0/24',
+ 'protocol': 'udp',
+ 'ethertype': 'IPv4',
+ 'l7_parameters': {},
+ 'source_port_range_max': 2000,
+ 'destination_port_range_min': 3000,
+ 'source_ip_prefix': '192.168.2.0/24',
+ 'logical_destination_port': None,
+ 'destination_port_range_max': None,
+ 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'}
+ }])
+
+ def _test_get_sfi_list(self, list_port_pair, correlation, sfc_encap):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_pair.return_value = {'port_pairs': [
+ {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'service_function_parameters': {'correlation': correlation},
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
+ 'name': 'osm_sfi'}]}
+
+ # call the VIM connector
+ filter_dict = {'name': 'osm_sfi', 'description': ''}
+ result = self.vimconn.get_sfi_list(filter_dict.copy())
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_pair.assert_called_with(**filter_dict)
+ # assert that the VIM connector successfully
+ # translated and returned the OpenStack result
+ self.assertEqual(result, [
+ {'ingress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'egress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
+ 'sfc_encap': sfc_encap,
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
+ 'name': 'osm_sfi'}])
+
+ @mock.patch.object(Client, 'list_port_pair')
+ def test_get_sfi_list_with_sfc_encap(self, list_port_pair):
+ self._test_get_sfi_list(list_port_pair, 'nsh', True)
+
+ @mock.patch.object(Client, 'list_port_pair')
+ def test_get_sfi_list_without_sfc_encap(self, list_port_pair):
+ self._test_get_sfi_list(list_port_pair, None, False)
+
+ @mock.patch.object(Client, 'list_port_pair_group')
+ def test_get_sf_list(self, list_port_pair_group):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_pair_group.return_value = {'port_pair_groups': [
+ {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
+ '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'port_pair_group_parameters': {},
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
+ 'name': 'osm_sf'}]}
+
+ # call the VIM connector
+ filter_dict = {'name': 'osm_sf', 'description': ''}
+ result = self.vimconn.get_sf_list(filter_dict.copy())
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_pair_group.assert_called_with(**filter_dict)
+ # assert that the VIM connector successfully
+ # translated and returned the OpenStack result
+ self.assertEqual(result, [
+ {'instances': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
+ '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
+ 'name': 'osm_sf'}])
+
+ def _test_get_sfp_list(self, list_port_chain, correlation, sfc_encap):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_chain.return_value = {'port_chains': [
+ {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25',
+ '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'],
+ 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e',
+ '1387ab44-82d7-11e7-9bb0-476337183905'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'chain_parameters': {'correlation': correlation},
+ 'chain_id': 40,
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
+ 'name': 'osm_sfp'}]}
+
+ # call the VIM connector
+ filter_dict = {'name': 'osm_sfp', 'description': ''}
+ result = self.vimconn.get_sfp_list(filter_dict.copy())
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_chain.assert_called_with(**filter_dict)
+ # assert that the VIM connector successfully
+ # translated and returned the OpenStack result
+ self.assertEqual(result, [
+ {'service_functions': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25',
+ '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'],
+ 'classifications': ['1333c2f4-82d7-11e7-a5df-9327f33d104e',
+ '1387ab44-82d7-11e7-9bb0-476337183905'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'sfc_encap': sfc_encap,
+ 'spi': 40,
+ 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
+ 'name': 'osm_sfp'}])
+
+ @mock.patch.object(Client, 'list_port_chain')
+ def test_get_sfp_list_with_sfc_encap(self, list_port_chain):
+ self._test_get_sfp_list(list_port_chain, 'nsh', True)
+
+ @mock.patch.object(Client, 'list_port_chain')
+ def test_get_sfp_list_without_sfc_encap(self, list_port_chain):
+ self._test_get_sfp_list(list_port_chain, None, False)
+
+ @mock.patch.object(Client, 'list_flow_classifier')
+ def test_get_classification(self, list_flow_classifier):
+ # what OpenStack is assumed to return to the VIM connector
+ list_flow_classifier.return_value = {'flow_classifiers': [
+ {'source_port_range_min': 2000,
+ 'destination_ip_prefix': '192.168.3.0/24',
+ 'protocol': 'udp',
+ 'description': '',
+ 'ethertype': 'IPv4',
+ 'l7_parameters': {},
+ 'source_port_range_max': 2000,
+ 'destination_port_range_min': 3000,
+ 'source_ip_prefix': '192.168.2.0/24',
+ 'logical_destination_port': None,
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'destination_port_range_max': None,
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
+ 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
+ 'name': 'fc1'}
+ ]}
+
+ # call the VIM connector
+ result = self.vimconn.get_classification(
+ '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d')
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_flow_classifier.assert_called_with(
+ id='22198366-d4e8-4d6b-b4d2-637d5d6cbb7d')
+ # assert that VIM connector successfully returned the OpenStack result
+ self.assertEqual(result,
+ {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
+ 'name': 'fc1',
+ 'description': '',
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'ctype': 'legacy_flow_classifier',
+ 'definition': {
+ 'source_port_range_min': 2000,
+ 'destination_ip_prefix': '192.168.3.0/24',
+ 'protocol': 'udp',
+ 'ethertype': 'IPv4',
+ 'l7_parameters': {},
+ 'source_port_range_max': 2000,
+ 'destination_port_range_min': 3000,
+ 'source_ip_prefix': '192.168.2.0/24',
+ 'logical_destination_port': None,
+ 'destination_port_range_max': None,
+ 'logical_source_port':
+ 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'}
+ })
+
+ @mock.patch.object(Client, 'list_flow_classifier')
+ def test_get_classification_many_results(self, list_flow_classifier):
+ # what OpenStack is assumed to return to the VIM connector
+ list_flow_classifier.return_value = {'flow_classifiers': [
+ {'source_port_range_min': 2000,
+ 'destination_ip_prefix': '192.168.3.0/24',
+ 'protocol': 'udp',
+ 'description': '',
+ 'ethertype': 'IPv4',
+ 'l7_parameters': {},
+ 'source_port_range_max': 2000,
+ 'destination_port_range_min': 3000,
+ 'source_ip_prefix': '192.168.2.0/24',
+ 'logical_destination_port': None,
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'destination_port_range_max': None,
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
+ 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
+ 'name': 'fc1'},
+ {'source_port_range_min': 1000,
+ 'destination_ip_prefix': '192.168.3.0/24',
+ 'protocol': 'udp',
+ 'description': '',
+ 'ethertype': 'IPv4',
+ 'l7_parameters': {},
+ 'source_port_range_max': 1000,
+ 'destination_port_range_min': 3000,
+ 'source_ip_prefix': '192.168.2.0/24',
+ 'logical_destination_port': None,
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'destination_port_range_max': None,
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
+ 'id': '3196bafc-82dd-11e7-a205-9bf6c14b0721',
+ 'name': 'fc2'}
+ ]}
+
+ # call the VIM connector
+ self.assertRaises(vimconn.vimconnConflictException,
+ self.vimconn.get_classification,
+ '3196bafc-82dd-11e7-a205-9bf6c14b0721')
+
+ # assert the VIM connector called OpenStack with the expected filter
+ list_flow_classifier.assert_called_with(
+ id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
+
+ @mock.patch.object(Client, 'list_flow_classifier')
+ def test_get_classification_no_results(self, list_flow_classifier):
+ # what OpenStack is assumed to return to the VIM connector
+ list_flow_classifier.return_value = {'flow_classifiers': []}
+
+ # call the VIM connector
+ self.assertRaises(vimconn.vimconnNotFoundException,
+ self.vimconn.get_classification,
+ '3196bafc-82dd-11e7-a205-9bf6c14b0721')
+
+ # assert the VIM connector called OpenStack with the expected filter
+ list_flow_classifier.assert_called_with(
+ id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
+
+ @mock.patch.object(Client, 'list_port_pair')
+ def test_get_sfi(self, list_port_pair):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_pair.return_value = {'port_pairs': [
+ {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'service_function_parameters': {'correlation': 'nsh'},
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
+ 'name': 'osm_sfi1'},
+ ]}
+
+ # call the VIM connector
+ result = self.vimconn.get_sfi('c121ebdd-7f2d-4213-b933-3325298a6966')
+
+ # assert the VIM connector called OpenStack with the expected filter
+ list_port_pair.assert_called_with(
+ id='c121ebdd-7f2d-4213-b933-3325298a6966')
+ # assert the VIM connector successfully returned the OpenStack result
+ self.assertEqual(result,
+ {'ingress_ports': [
+ '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
+ 'egress_ports': [
+ '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
+ 'sfc_encap': True,
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
+ 'name': 'osm_sfi1'})
+
+ @mock.patch.object(Client, 'list_port_pair')
+ def test_get_sfi_many_results(self, list_port_pair):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_pair.return_value = {'port_pairs': [
+ {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'service_function_parameters': {'correlation': 'nsh'},
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
+ 'name': 'osm_sfi1'},
+ {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
+ 'service_function_parameters': {'correlation': 'nsh'},
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'c0436d92-82db-11e7-8f9c-5fa535f1261f',
+ 'name': 'osm_sfi2'}
+ ]}
+
+ # call the VIM connector
+ self.assertRaises(vimconn.vimconnConflictException,
+ self.vimconn.get_sfi,
+ 'c0436d92-82db-11e7-8f9c-5fa535f1261f')
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_pair.assert_called_with(
+ id='c0436d92-82db-11e7-8f9c-5fa535f1261f')
+
+ @mock.patch.object(Client, 'list_port_pair')
+ def test_get_sfi_no_results(self, list_port_pair):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_pair.return_value = {'port_pairs': []}
+
+ # call the VIM connector
+ self.assertRaises(vimconn.vimconnNotFoundException,
+ self.vimconn.get_sfi,
+ 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_pair.assert_called_with(
+ id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
+
+ @mock.patch.object(Client, 'list_port_pair_group')
+ def test_get_sf(self, list_port_pair_group):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_pair_group.return_value = {'port_pair_groups': [
+ {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'port_pair_group_parameters': {},
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
+ 'name': 'osm_sf1'}
+ ]}
+
+ # call the VIM connector
+ result = self.vimconn.get_sf('b22892fc-82d9-11e7-ae85-0fea6a3b3757')
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_pair_group.assert_called_with(
+ id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
+ # assert that VIM connector successfully returned the OpenStack result
+ self.assertEqual(result,
+ {'instances': [
+ '08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
+ 'name': 'osm_sf1'})
+
+ @mock.patch.object(Client, 'list_port_pair_group')
+ def test_get_sf_many_results(self, list_port_pair_group):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_pair_group.return_value = {'port_pair_groups': [
+ {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'port_pair_group_parameters': {},
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
+ 'name': 'osm_sf1'},
+ {'port_pairs': ['0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'port_pair_group_parameters': {},
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': 'b22892fc-82d9-11e7-ae85-0fea6a3b3757',
+ 'name': 'osm_sf2'}
+ ]}
+
+ # call the VIM connector
+ self.assertRaises(vimconn.vimconnConflictException,
+ self.vimconn.get_sf,
+ 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_pair_group.assert_called_with(
+ id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
+
+ @mock.patch.object(Client, 'list_port_pair_group')
+ def test_get_sf_no_results(self, list_port_pair_group):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_pair_group.return_value = {'port_pair_groups': []}
+
+ # call the VIM connector
+ self.assertRaises(vimconn.vimconnNotFoundException,
+ self.vimconn.get_sf,
+ 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_pair_group.assert_called_with(
+ id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
+
+ @mock.patch.object(Client, 'list_port_chain')
+ def test_get_sfp(self, list_port_chain):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_chain.return_value = {'port_chains': [
+ {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
+ 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'chain_parameters': {'correlation': 'nsh'},
+ 'chain_id': 40,
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
+ 'name': 'osm_sfp1'}]}
+
+ # call the VIM connector
+ result = self.vimconn.get_sfp('821bc9be-82d7-11e7-8ce3-23a08a27ab47')
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_chain.assert_called_with(
+ id='821bc9be-82d7-11e7-8ce3-23a08a27ab47')
+ # assert that VIM connector successfully returned the OpenStack result
+ self.assertEqual(result,
+ {'service_functions': [
+ '7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
+ 'classifications': [
+ '1333c2f4-82d7-11e7-a5df-9327f33d104e'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'sfc_encap': True,
+ 'spi': 40,
+ 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
+ 'name': 'osm_sfp1'})
+
+ @mock.patch.object(Client, 'list_port_chain')
+ def test_get_sfp_many_results(self, list_port_chain):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_chain.return_value = {'port_chains': [
+ {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
+ 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'chain_parameters': {'correlation': 'nsh'},
+ 'chain_id': 40,
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
+ 'name': 'osm_sfp1'},
+ {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
+ 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
+ 'description': '',
+ 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'chain_parameters': {'correlation': 'nsh'},
+ 'chain_id': 50,
+ 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
+ 'id': '5d002f38-82de-11e7-a770-f303f11ce66a',
+ 'name': 'osm_sfp2'}
+ ]}
+
+ # call the VIM connector
+ self.assertRaises(vimconn.vimconnConflictException,
+ self.vimconn.get_sfp,
+ '5d002f38-82de-11e7-a770-f303f11ce66a')
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_chain.assert_called_with(
+ id='5d002f38-82de-11e7-a770-f303f11ce66a')
+
+ @mock.patch.object(Client, 'list_port_chain')
+ def test_get_sfp_no_results(self, list_port_chain):
+ # what OpenStack is assumed to return to the VIM connector
+ list_port_chain.return_value = {'port_chains': []}
+
+ # call the VIM connector
+ self.assertRaises(vimconn.vimconnNotFoundException,
+ self.vimconn.get_sfp,
+ '5d002f38-82de-11e7-a770-f303f11ce66a')
+
+ # assert that VIM connector called OpenStack with the expected filter
+ list_port_chain.assert_called_with(
+ id='5d002f38-82de-11e7-a770-f303f11ce66a')
+
+ @mock.patch.object(Client, 'delete_flow_classifier')
+ def test_delete_classification(self, delete_flow_classifier):
+ result = self.vimconn.delete_classification(
+ '638f957c-82df-11e7-b7c8-132706021464')
+ delete_flow_classifier.assert_called_with(
+ '638f957c-82df-11e7-b7c8-132706021464')
+ self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
+
+ @mock.patch.object(Client, 'delete_port_pair')
+ def test_delete_sfi(self, delete_port_pair):
+ result = self.vimconn.delete_sfi(
+ '638f957c-82df-11e7-b7c8-132706021464')
+ delete_port_pair.assert_called_with(
+ '638f957c-82df-11e7-b7c8-132706021464')
+ self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
+
+ @mock.patch.object(Client, 'delete_port_pair_group')
+ def test_delete_sf(self, delete_port_pair_group):
+ result = self.vimconn.delete_sf('638f957c-82df-11e7-b7c8-132706021464')
+ delete_port_pair_group.assert_called_with(
+ '638f957c-82df-11e7-b7c8-132706021464')
+ self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
+
+ @mock.patch.object(Client, 'delete_port_chain')
+ def test_delete_sfp(self, delete_port_chain):
+ result = self.vimconn.delete_sfp(
+ '638f957c-82df-11e7-b7c8-132706021464')
+ delete_port_chain.assert_called_with(
+ '638f957c-82df-11e7-b7c8-132706021464')
+ self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
+
+
+if __name__ == '__main__':
+ unittest.main()
--- /dev/null
+# -*- coding: utf-8 -*-
+
+##
+# Copyright 2016-2017 VMware Inc.
+# This file is part of ETSI OSM
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: osslegalrouting@vmware.com
+##
+
+
+from osm_ro.vimconn_vmware import vimconnector
+from osm_ro.vimconn import vimconnUnexpectedResponse,vimconnNotFoundException
+from pyvcloud.vcloudair import VCA,VCS
+from pyvcloud.vapp import VAPP
+from pyvcloud import Http
+from pyvcloud.schema.vcd.v1_5.schemas.vcloud import vdcType,networkType,catalogType, \
+ vAppType,taskType
+import unittest
+import mock
+import test_vimconn_vmware_xml_response as xml_resp
+
+class TestVimconn_VMware(unittest.TestCase):
+ def setUp(self):
+ config = { "admin_password": "admin",
+ "admin_username":"user",
+ "nsx_user": "nsx",
+ "nsx_password": "nsx",
+ "nsx_manager":"https://test-nsx" }
+
+ self.vca = VCA(host='test',
+ username='user',
+ service_type='standalone',
+ version='5.9',
+ verify=False,
+ log=False)
+
+ self.session = VCS('https://test/api/session',
+ 'test',
+ 'test',
+ None,
+ 'https://test/api/org/a93c',
+ 'https://test/api/org/a93c',
+ version='5.9')
+
+ self.vim = vimconnector(uuid='12354',
+ name='test',
+ tenant_id='abc1234',
+ tenant_name='test',
+ url='https://test',
+ config=config)
+
+
+ @mock.patch.object(vimconnector,'get_vdc_details')
+ @mock.patch.object(vimconnector,'connect')
+ @mock.patch.object(VCA,'get_networks')
+ def test_get_network_not_found(self,get_networks, connect, get_vdc_details):
+ vdc_xml_resp = xml_resp.vdc_xml_response
+ # created vdc object
+ vdc = vdcType.parseString(vdc_xml_resp,True)
+ # assumed return value from VIM connector
+ get_vdc_details.return_value = vdc
+ self.vim.vca = self.vim.connect()
+ network_xml_resp = xml_resp.network_xml_response
+ networks = networkType.parseString(network_xml_resp, True)
+ (self.vim.vca).get_networks.return_value = [networks]
+ # call to VIM connector method with invalid id
+ self.assertRaises(vimconnNotFoundException,self.vim.get_network,'mgmt-net')
+
+ @mock.patch.object(vimconnector,'get_vdc_details')
+ @mock.patch.object(vimconnector,'connect')
+ @mock.patch.object(VCA,'get_networks')
+ def test_get_network(self,get_networks, connect, get_vdc_details):
+ net_id = '5c04dc6d-6096-47c6-b72b-68f19013d491'
+ vdc_xml_resp = xml_resp.vdc_xml_response
+ # created vdc object
+ vdc = vdcType.parseString(vdc_xml_resp,True)
+ # created network object
+ network_xml_resp = xml_resp.network_xml_response
+ networks = networkType.parseString(network_xml_resp, True)
+ # assumed return value from VIM connector
+ get_vdc_details.return_value = vdc
+ self.vim.vca = self.vim.connect()
+ # assumed return value from VIM connector
+ (self.vim.vca).get_networks.return_value = [networks]
+ # call to VIM connector method with network_id
+ result = self.vim.get_network(net_id)
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(net_id, result['id'])
+
+ @mock.patch.object(vimconnector,'get_vdc_details')
+ @mock.patch.object(vimconnector,'connect')
+ @mock.patch.object(VCA,'get_networks')
+ def test_get_network_list_not_found(self,get_networks, connect, get_vdc_details):
+ vdc_xml_resp = xml_resp.vdc_xml_response
+ # created vdc object
+ vdc = vdcType.parseString(vdc_xml_resp,True)
+ # assumed return value from VIM connector
+ get_vdc_details.return_value = vdc
+ self.vim.vca = self.vim.connect()
+
+ network_xml_resp = xml_resp.network_xml_response
+ networks = networkType.parseString(network_xml_resp, True)
+ (self.vim.vca).get_networks.return_value = [networks]
+ # call to VIM connector method with network_id
+ result = self.vim.get_network_list({'id':'45hdfg-345nb-345'})
+
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(list(), result)
+
+ @mock.patch.object(vimconnector,'get_vdc_details')
+ @mock.patch.object(vimconnector,'connect')
+ @mock.patch.object(VCA,'get_networks')
+ def test_get_network_list(self,get_networks, connect, get_vdc_details):
+ vdc_xml_resp = xml_resp.vdc_xml_response
+ net_id = '5c04dc6d-6096-47c6-b72b-68f19013d491'
+ vdc = vdcType.parseString(vdc_xml_resp,True)
+ # created network object
+ network_xml_resp = xml_resp.network_xml_response
+ networks = networkType.parseString(network_xml_resp, True)
+ # assumed return value from VIM connector
+ get_vdc_details.return_value = vdc
+ self.vim.vca = self.vim.connect()
+ # assumed return value from VIM connector
+ (self.vim.vca).get_networks.return_value = [networks]
+
+ # call to VIM connector method with network_id
+ result = self.vim.get_network_list({'id': net_id})
+ # assert verified expected and return result from VIM connector
+ for item in result:
+ self.assertEqual(item.get('id'), net_id)
+ self.assertEqual(item.get('status'), 'ACTIVE')
+ self.assertEqual(item.get('shared'), False)
+
+ @mock.patch.object(vimconnector,'create_network_rest')
+ def test_new_network(self, create_network_rest):
+ create_net_xml_resp = xml_resp.create_network_xml_response
+ net_name = 'Test_network'
+ net_type = 'bridge'
+ # assumed return value from VIM connector
+ create_network_rest.return_value = create_net_xml_resp
+ # call to VIM connector method with network_id
+ result = self.vim.new_network(net_name, net_type)
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(result, 'df1956fa-da04-419e-a6a2-427b6f83788f')
+
+ @mock.patch.object(vimconnector, 'create_network_rest')
+ def test_new_network_not_created(self, create_network_rest):
+ # assumed return value from VIM connector
+ create_network_rest.return_value = """<?xml version="1.0" encoding="UTF-8"?>
+ <OrgVdcNetwork></OrgVdcNetwork>"""
+
+ # assert verified expected and return result from VIM connector
+ self.assertRaises(vimconnUnexpectedResponse,self.vim.new_network,
+ 'test_net',
+ 'bridge')
+
+ @mock.patch.object(vimconnector, 'connect')
+ @mock.patch.object(vimconnector, 'get_network_action')
+ @mock.patch.object(vimconnector, 'connect_as_admin')
+ @mock.patch.object(vimconnector, 'delete_network_action')
+ def test_delete_network(self, delete_network_action, connect_as_admin, get_network_action, connect):
+ delete_net_xml_resp = xml_resp.delete_network_xml_response
+ # assumed return value from VIM connector
+ connect.return_value = self.vca
+ self.vim.vca = self.vim.connect()
+ get_network_action.return_value = delete_net_xml_resp
+ connect_as_admin.return_value = self.vca
+ delete_network_action.return_value = True
+ # call to VIM connector method with network_id
+ result = self.vim.delete_network('0a55e5d1-43a2-4688-bc92-cb304046bf87')
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(result, '0a55e5d1-43a2-4688-bc92-cb304046bf87')
+
+ @mock.patch.object(vimconnector, 'get_vcd_network')
+ def test_delete_network_not_found(self, get_vcd_network):
+ # assumed return value from VIM connector
+ get_vcd_network.return_value = False
+ # assert verified expected and return result from VIM connector
+ self.assertRaises(vimconnNotFoundException,self.vim.delete_network,
+ '2a23e5d1-42a2-0648-bc92-cb508046bf87')
+
+ def test_get_flavor(self):
+ flavor_data = {'a646eb8a-95bd-4e81-8321-5413ee72b62e': {'disk': 10,
+ 'vcpus': 1,
+ 'ram': 1024}}
+ vimconnector.flavorlist = flavor_data
+ result = self.vim.get_flavor('a646eb8a-95bd-4e81-8321-5413ee72b62e')
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(result, flavor_data['a646eb8a-95bd-4e81-8321-5413ee72b62e'])
+
+ def test_get_flavor_not_found(self):
+ vimconnector.flavorlist = {}
+ # assert verified expected and return result from VIM connector
+ self.assertRaises(vimconnNotFoundException,self.vim.get_flavor,
+ 'a646eb8a-95bd-4e81-8321-5413ee72b62e')
+
+ def test_new_flavor(self):
+ flavor_data = {'disk': 10, 'vcpus': 1, 'ram': 1024}
+ result = self.vim.new_flavor(flavor_data)
+ # assert verified expected and return result from VIM connector
+ self.assertIsNotNone(result)
+
+ def test_delete_flavor(self):
+ flavor_data = {'2cb3dffb-5c51-4355-8406-28553ead28ac': {'disk': 10,
+ 'vcpus': 1,
+ 'ram': 1024}}
+ vimconnector.flavorlist = flavor_data
+ # return value from VIM connector
+ result = self.vim.delete_flavor('2cb3dffb-5c51-4355-8406-28553ead28ac')
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(result, '2cb3dffb-5c51-4355-8406-28553ead28ac')
+
+ @mock.patch.object(vimconnector,'connect_as_admin')
+ @mock.patch.object(vimconnector,'connect')
+ @mock.patch.object(Http,'get')
+ @mock.patch.object(VCS,'get_vcloud_headers')
+ def test_delete_image_not_found(self, get_vcloud_headers, get, connect, connect_as_admin):
+ # assumed return value from VIM connector
+ connect.return_value = self.vca
+ self.vim.vca = self.vim.connect()
+ # assumed return value from VIM connector
+ connect_as_admin.return_value = self.vca
+ self.vca.host = connect_as_admin.return_value.host
+ self.vca.vcloud_session = self.session
+ get_vcloud_headers.return_value = {'Accept':'application/*+xml;version=5.9',
+ 'x-vcloud-authorization': '638bfee6cb5f435abc3480f480817254'}
+ get_vcloud_headers.return_value = self.vca.vcloud_session.get_vcloud_headers()
+ # assert verified expected and return result from VIM connector
+ self.assertRaises(vimconnNotFoundException, self.vim.delete_image, 'invali3453')
+
+ @mock.patch.object(vimconnector,'connect')
+ @mock.patch.object(VCA,'get_catalogs')
+ def test_get_image_list(self, get_catalogs, connect):
+ catalog1 = xml_resp.catalog1_xml_response
+ catalog2 = xml_resp.catalog2_xml_response
+
+ catalogs = [catalogType.parseString(cat, True) for cat in catalog1, catalog2]
+ connect.return_value = self.vca
+ self.vim.vca = self.vim.connect()
+ # assumed return value from VIM connector
+ self.vim.vca.get_catalogs.return_value = catalogs
+ result = self.vim.get_image_list({'id': '32ccb082-4a65-41f6-bcd6-38942e8a3829'})
+ # assert verified expected and return result from VIM connector
+ for item in result:
+ self.assertEqual(item['id'], '32ccb082-4a65-41f6-bcd6-38942e8a3829')
+
+ @mock.patch.object(vimconnector,'get_vapp_details_rest')
+ @mock.patch.object(vimconnector,'get_vdc_details')
+ def test_get_vminstance(self, get_vdc_details, get_vapp_details_rest):
+ vapp_info = {'status': '4',
+ 'acquireMksTicket': {'href': 'https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/screen/action/acquireMksTicket',
+ 'type': 'application/vnd.vmware.vcloud.mksTicket+xml', 'rel': 'screen:acquireMksTicket'},
+ 'vm_virtual_hardware': {'disk_edit_href': 'https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/disks', 'disk_size': '40960'},
+ 'name': 'Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa',
+ 'created': '2017-09-21T01:15:31.627-07:00',
+ 'IsEnabled': 'true',
+ 'EndAddress': '12.16.24.199',
+ 'interfaces': [{'MACAddress': '00:50:56:01:12:a2',
+ 'NetworkConnectionIndex': '0',
+ 'network': 'testing_T6nODiW4-68f68d93-0350-4d86-b40b-6e74dedf994d',
+ 'IpAddressAllocationMode': 'DHCP',
+ 'IsConnected': 'true',
+ 'IpAddress': '12.16.24.200'}],
+ 'ovfDescriptorUploaded': 'true',
+ 'nestedHypervisorEnabled': 'false',
+ 'Gateway': '12.16.24.1',
+ 'acquireTicket': {'href': 'https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/screen/action/acquireTicket',
+ 'rel': 'screen:acquireTicket'},
+ 'vmuuid': '47d12505-5968-4e16-95a7-18743edb0c8b',
+ 'Netmask': '255.255.255.0',
+ 'StartAddress': '12.16.24.100',
+ 'primarynetwork': '0',
+ 'networkname': 'External-Network-1074',
+ 'IsInherited': 'false',
+ 'deployed': 'true'}
+ # created vdc object
+ vdc_xml_resp = xml_resp.vdc_xml_response
+ vdc = vdcType.parseString(vdc_xml_resp,True)
+ # assumed return value from VIM connector
+ get_vdc_details.return_value = vdc
+ get_vapp_details_rest.return_value = vapp_info
+
+ result = self.vim.get_vminstance('47d12505-5968-4e16-95a7-18743edb0c8b')
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(result['status'], 'ACTIVE')
+ self.assertEqual(result['hostId'], '47d12505-5968-4e16-95a7-18743edb0c8b')
+
+ @mock.patch.object(VCA,'get_vapp')
+ @mock.patch.object(vimconnector,'connect')
+ @mock.patch.object(vimconnector,'get_namebyvappid')
+ @mock.patch.object(vimconnector,'get_vdc_details')
+ def test_delete_vminstance(self, get_vdc_details, get_namebyvappid, connect, vapp):
+ vm_id = '4f6a9b49-e92d-4935-87a1-0e4dc9c3a069'
+ vm_name = 'Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa'
+ # created vdc object
+ vdc_xml_resp = xml_resp.vdc_xml_response
+ vdc = vdcType.parseString(vdc_xml_resp,True)
+ # assumed return value from VIM connector
+ connect.return_value = self.vca
+ self.vim.vca = self.vim.connect()
+ get_namebyvappid.return_name = vm_name
+ vapp.return_value = None
+ # call to VIM connector method
+ result = self.vim.delete_vminstance(vm_id)
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(result, vm_id)
+
+ @mock.patch.object(vimconnector,'get_network_id_by_name')
+ @mock.patch.object(vimconnector,'get_vm_pci_details')
+ @mock.patch.object(VCA,'get_vapp')
+ @mock.patch.object(vimconnector,'connect')
+ @mock.patch.object(vimconnector,'get_namebyvappid')
+ @mock.patch.object(vimconnector,'get_vdc_details')
+ def test_refresh_vms_status(self, get_vdc_details, get_namebyvappid, connect,
+ get_vapp, get_vm_pci_details,
+ get_network_id_by_name):
+ headers = {'Accept':'application/*+xml;version=5.9',
+ 'x-vcloud-authorization': '638bfee6cb5f435abc3480f480817254'}
+ vm_id = '05e6047b-6938-4275-8940-22d1ea7245b8'
+
+ vapp_resp = xml_resp.vapp_xml_response
+ # created vdc object
+ vdc_xml_resp = xml_resp.vdc_xml_response
+ vdc = vdcType.parseString(vdc_xml_resp,True)
+ # assumed return value from VIM connector
+ get_vdc_details.return_value = vdc
+ connect.return_value = self.vca
+
+ self.vim.vca = self.vim.connect()
+ get_namebyvappid.return_value = 'Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa'
+ get_vm_pci_details.return_value = {'host_name': 'test-esx-1.corp.local', 'host_ip': '12.19.24.31'}
+ get_vapp.return_value = VAPP(vAppType.parseString(vapp_resp, True), headers, False)
+ get_network_id_by_name.return_value = '47d12505-5968-4e16-95a7-18743edb0c8b'
+ # call to VIM connector method
+ result = self.vim.refresh_vms_status([vm_id])
+ for attr in result[vm_id]:
+ if attr == 'status':
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(result[vm_id][attr], 'ACTIVE')
+
+ @mock.patch.object(vimconnector,'get_vcd_network')
+ def test_refresh_nets_status(self, get_vcd_network):
+ net_id = 'c2d0f28f-d38b-4588-aecc-88af3d4af58b'
+ network_dict = {'status': '1','isShared': 'false','IpScope': '',
+ 'EndAddress':'12.19.21.15',
+ 'name': 'testing_gwyRXlvWYL1-9ebb6d7b-5c74-472f-be77-963ed050d44d',
+ 'Dns1': '12.19.21.10', 'IpRanges': '',
+ 'Gateway': '12.19.21.23', 'Netmask': '255.255.255.0',
+ 'RetainNetInfoAcrossDeployments': 'false',
+ 'IpScopes': '', 'IsEnabled': 'true', 'DnsSuffix': 'corp.local',
+ 'StartAddress': '12.19.21.11', 'IpRange': '',
+ 'Configuration': '', 'FenceMode': 'bridged',
+ 'IsInherited': 'true', 'uuid': 'c2d0f28f-d38b-4588-aecc-88af3d4af58b'}
+ # assumed return value from VIM connector
+ get_vcd_network.return_value = network_dict
+ result = self.vim.refresh_nets_status([net_id])
+ # assert verified expected and return result from VIM connector
+ for attr in result[net_id]:
+ if attr == 'status':
+ self.assertEqual(result[net_id][attr], 'ACTIVE')
+
+ @mock.patch.object(VCA,'block_until_completed')
+ @mock.patch.object(VCA,'get_vapp')
+ @mock.patch.object(vimconnector,'connect')
+ @mock.patch.object(vimconnector,'get_namebyvappid')
+ @mock.patch.object(vimconnector,'get_vdc_details')
+ def test_action_vminstance(self, get_vdc_details, get_namebyvappid, connect, get_vapp, block):
+ task_resp = xml_resp.task_xml
+ vm_id = '05e6047b-6938-4275-8940-22d1ea7245b8'
+ # created vdc object
+ vdc_xml_resp = xml_resp.vdc_xml_response
+ vdc = vdcType.parseString(vdc_xml_resp,True)
+ # assumed return value from VIM connector
+ get_vdc_details.return_value = vdc
+ get_namebyvappid.return_value = 'Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa'
+ connect.return_value = self.vca
+ self.vim.vca = self.vim.connect()
+ get_vapp.return_value.undeploy.return_value = taskType.parseString(task_resp, True)
+ block.return_value = True
+ # call to VIM connector method
+ result = self.vim.action_vminstance(vm_id,{'shutdown': None})
+ # assert verified expected and return result from VIM connector
+ self.assertEqual(result, None)
--- /dev/null
+# -*- coding: utf-8 -*-\r
+\r
+##\r
+# Copyright 2016-2017 VMware Inc.\r
+# This file is part of ETSI OSM\r
+# All Rights Reserved.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License"); you may\r
+# not use this file except in compliance with the License. You may obtain\r
+# a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+# License for the specific language governing permissions and limitations\r
+# under the License.\r
+#\r
+# For those usages not covered by the Apache License, Version 2.0 please\r
+# contact: osslegalrouting@vmware.com\r
+##\r
+\r
+vdc_xml_response = """<?xml version="1.0" encoding="UTF-8"?>\r
+ <Vdc xmlns="http://www.vmware.com/vcloud/v1.5" status="1" name="Org3-VDC-PVDC1" id="urn:vcloud:vdc:2584137f-6541-4c04-a2a2-e56bfca14c69" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69" type="application/vnd.vmware.vcloud.vdc+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://localhost/api/v1.5/schema/master.xsd">\r
+ <Link rel="up" href="https://localhost/api/org/2cb3dffb-5c51-4355-8406-28553ead28ac" type="application/vnd.vmware.vcloud.org+xml"/>\r
+ <Link rel="down" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>\r
+ <Link rel="edit" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69" type="application/vnd.vmware.vcloud.vdc+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/action/uploadVAppTemplate" type="application/vnd.vmware.vcloud.uploadVAppTemplateParams+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/media" type="application/vnd.vmware.vcloud.media+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/action/instantiateOvf" type="application/vnd.vmware.vcloud.instantiateOvfParams+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/action/instantiateVAppTemplate" type="application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/action/cloneVApp" type="application/vnd.vmware.vcloud.cloneVAppParams+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/action/cloneVAppTemplate" type="application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/action/cloneMedia" type="application/vnd.vmware.vcloud.cloneMediaParams+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/action/captureVApp" type="application/vnd.vmware.vcloud.captureVAppParams+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/action/composeVApp" type="application/vnd.vmware.vcloud.composeVAppParams+xml"/>\r
+ <Link rel="add" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/disk" type="application/vnd.vmware.vcloud.diskCreateParams+xml"/>\r
+ <Link rel="edgeGateways" href="https://localhost/api/admin/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/edgeGateways" type="application/vnd.vmware.vcloud.query.records+xml"/>\r
+ <Link rel="add" href="https://localhost/api/admin/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/networks" type="application/vnd.vmware.vcloud.orgVdcNetwork+xml"/>\r
+ <Link rel="orgVdcNetworks" href="https://localhost/api/admin/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69/networks" type="application/vnd.vmware.vcloud.query.records+xml"/>\r
+ <Link rel="alternate" href="https://localhost/api/admin/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69" type="application/vnd.vmware.admin.vdc+xml"/>\r
+ <Description>Org3-VDC-PVDC1</Description>\r
+ <AllocationModel>AllocationVApp</AllocationModel>\r
+ <ComputeCapacity>\r
+ <Cpu>\r
+ <Units>MHz</Units>\r
+ <Allocated>0</Allocated>\r
+ <Limit>0</Limit>\r
+ <Reserved>0</Reserved>\r
+ <Used>2000</Used>\r
+ <Overhead>0</Overhead>\r
+ </Cpu>\r
+ <Memory>\r
+ <Units>MB</Units>\r
+ <Allocated>0</Allocated>\r
+ <Limit>0</Limit>\r
+ <Reserved>0</Reserved>\r
+ <Used>2048</Used>\r
+ <Overhead>71</Overhead>\r
+ </Memory>\r
+ </ComputeCapacity>\r
+ <ResourceEntities>\r
+ <ResourceEntity href="https://localhost/api/vAppTemplate/vappTemplate-2999a787-ca96-4d1c-8b7c-9d0a8bd14bce" name="cirros" type="application/vnd.vmware.vcloud.vAppTemplate+xml"/>\r
+ <ResourceEntity href="https://localhost/api/vAppTemplate/vappTemplate-324649a3-d263-4446-aace-4e2c801a85bd" name="cirros_10" type="application/vnd.vmware.vcloud.vAppTemplate+xml"/>\r
+ <ResourceEntity href="https://localhost/api/vAppTemplate/vappTemplate-8ea35d43-0c72-4267-bac9-42e4a5248c32" name="Test_Cirros" type="application/vnd.vmware.vcloud.vAppTemplate+xml"/>\r
+ <ResourceEntity href="https://localhost/api/vAppTemplate/vappTemplate-9bf292a2-58c4-4d4b-995b-623e88b74226" name="Ubuntu-vm" type="application/vnd.vmware.vcloud.vAppTemplate+xml"/>\r
+ <ResourceEntity href="https://localhost/api/vAppTemplate/vappTemplate-be93140e-da0d-4b8c-8ab4-06d132bf47c0" name="Ubuntu16" type="application/vnd.vmware.vcloud.vAppTemplate+xml"/>\r
+ <ResourceEntity href="https://localhost/api/vApp/vapp-0da5344d-4d65-4362-bac6-e8524c97edb1" name="Inst10.linux1.a-e9f75c31-eadf-4b48-9a5e-d957314530d7" type="application/vnd.vmware.vcloud.vApp+xml"/>\r
+ <ResourceEntity href="https://localhost/api/vApp/vapp-3e0df975-1380-4544-9f25-0683f9eb41f0" name="Inst12.linux1.a-93854e6d-d87c-4f0a-ba10-eaf59d7555bf" type="application/vnd.vmware.vcloud.vApp+xml"/>\r
+ <ResourceEntity href="https://localhost/api/vApp/vapp-6f5848b8-5498-4854-a35e-45cb25b8fdb0" name="Inst11.linux1.a-5ca666e8-e077-4268-aff2-99960af28eb5" type="application/vnd.vmware.vcloud.vApp+xml"/>\r
+ <ResourceEntity href="https://localhost/api/vApp/vapp-76510a06-c949-4bea-baad-629daaccb84a" name="cirros_nsd.cirros_vnfd__1.a-a9c957c4-29a5-4559-a630-00ae028592f7" type="application/vnd.vmware.vcloud.vApp+xml"/>\r
+ </ResourceEntities><AvailableNetworks><Network href="https://localhost/api/network/1627b438-68bf-44be-800c-8f48029761f6" name="default-17c27654-2a45-4713-a799-94cb91de2610" type="application/vnd.vmware.vcloud.network+xml"/>\r
+ <Network href="https://localhost/api/network/190e9e04-a904-412b-877e-92d8e8699abd" name="cirros_nsd.cirros_nsd_vld1-86c861a9-d985-4e31-9c20-21de1e8a619d" type="application/vnd.vmware.vcloud.network+xml"/>\r
+ <Network href="https://localhost/api/network/3838c23e-cb0e-492f-a91f-f3352918ff8b" name="cirros_nsd.cirros_nsd_vld1-75ce0375-b2e6-4b7f-b821-5b395276bcd8" type="application/vnd.vmware.vcloud.network+xml"/>\r
+ <Network href="https://localhost/api/network/5aca5c32-c0a2-4e1b-980e-8fd906a49f4e" name="default-60a54140-66dd-4806-8ca3-069d34530478" type="application/vnd.vmware.vcloud.network+xml"/>\r
+ <Network href="https://localhost/api/network/de854aa2-0b77-4ace-a696-85494a3dc3c4" name="default-971acee6-0298-4085-b107-7601bc8c8712" type="application/vnd.vmware.vcloud.network+xml"/>\r
+ </AvailableNetworks>\r
+ <Capabilities>\r
+ <SupportedHardwareVersions>\r
+ <SupportedHardwareVersion>vmx-04</SupportedHardwareVersion>\r
+ <SupportedHardwareVersion>vmx-07</SupportedHardwareVersion>\r
+ <SupportedHardwareVersion>vmx-08</SupportedHardwareVersion>\r
+ <SupportedHardwareVersion>vmx-09</SupportedHardwareVersion>\r
+ <SupportedHardwareVersion>vmx-10</SupportedHardwareVersion>\r
+ <SupportedHardwareVersion>vmx-11</SupportedHardwareVersion>\r
+ </SupportedHardwareVersions>\r
+ </Capabilities>\r
+ <NicQuota>0</NicQuota>\r
+ <NetworkQuota>1000</NetworkQuota>\r
+ <UsedNetworkCount>0</UsedNetworkCount>\r
+ <VmQuota>0</VmQuota>\r
+ <IsEnabled>true</IsEnabled>\r
+ <VdcStorageProfiles>\r
+ <VdcStorageProfile href="https://localhost/api/vdcStorageProfile/3b82941c-11ed-407e-ada0-42d282fcd425" name="NFS Storage Policy" type="application/vnd.vmware.vcloud.vdcStorageProfile+xml"/>\r
+ <VdcStorageProfile href="https://localhost/api/vdcStorageProfile/950701fb-2b8a-4808-80f1-27d1170a2bfc" name="*" type="application/vnd.vmware.vcloud.vdcStorageProfile+xml"/>\r
+ </VdcStorageProfiles>\r
+ <VCpuInMhz2>1000</VCpuInMhz2>\r
+ </Vdc>"""\r
+\r
+network_xml_response = """<?xml version="1.0" encoding="UTF-8"?>\r
+ <OrgVdcNetwork xmlns="http://www.vmware.com/vcloud/v1.5" status="1" name="testing_6XXftDTroat1-03b18565-de01-4154-af51-8dbea42f0d84" id="urn:vcloud:network:5c04dc6d-6096-47c6-b72b-68f19013d491" href="https://localhost/api/network/5c04dc6d-6096-47c6-b72b-68f19013d491" type="application/vnd.vmware.vcloud.orgVdcNetwork+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://localhost/api/v1.5/schema/master.xsd">\r
+ <Link rel="up" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69" type="application/vnd.vmware.vcloud.vdc+xml"/>\r
+ <Link rel="down" href="https://localhost/api/network/5c04dc6d-6096-47c6-b72b-68f19013d491/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>\r
+ <Link rel="down" href="https://localhost/api/network/5c04dc6d-6096-47c6-b72b-68f19013d491/allocatedAddresses/" type="application/vnd.vmware.vcloud.allocatedNetworkAddress+xml"/>\r
+ <Description>Openmano created</Description>\r
+ <Configuration>\r
+ <IpScopes>\r
+ <IpScope>\r
+ <IsInherited>true</IsInherited>\r
+ <Gateway>12.169.24.23</Gateway>\r
+ <Netmask>255.255.255.0</Netmask>\r
+ <Dns1>12.169.24.102</Dns1>\r
+ <DnsSuffix>corp.local</DnsSuffix>\r
+ <IsEnabled>true</IsEnabled>\r
+ <IpRanges>\r
+ <IpRange>\r
+ <StartAddress>12.169.24.115</StartAddress>\r
+ <EndAddress>12.169.241.150</EndAddress>\r
+ </IpRange>\r
+ </IpRanges>\r
+ </IpScope>\r
+ </IpScopes>\r
+ <FenceMode>bridged</FenceMode>\r
+ <RetainNetInfoAcrossDeployments>false</RetainNetInfoAcrossDeployments>\r
+ </Configuration>\r
+ <IsShared>false</IsShared>\r
+ </OrgVdcNetwork>"""\r
+\r
+delete_network_xml_response = """<?xml version="1.0" encoding="UTF-8"?>\r
+ <OrgVdcNetwork xmlns="http://www.vmware.com/vcloud/v1.5" status="1" name="testing_negjXxdlB-7fdcf9f3-de32-4ae6-b9f9-fb725a80a74f" id="urn:vcloud:network:0a55e5d1-43a2-4688-bc92-cb304046bf87" href="https://localhost/api/network/0a55e5d1-43a2-4688-bc92-cb304046bf87" type="application/vnd.vmware.vcloud.orgVdcNetwork+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://localhost/api/v1.5/schema/master.xsd">\r
+ <Link rel="up" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69" type="application/vnd.vmware.vcloud.vdc+xml"/>\r
+ <Link rel="down" href="https://localhost/api/network/0a55e5d1-43a2-4688-bc92-cb304046bf87/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>\r
+ <Link rel="down" href="https://localhost/api/network/0a55e5d1-43a2-4688-bc92-cb304046bf87/allocatedAddresses/" type="application/vnd.vmware.vcloud.allocatedNetworkAddress+xml"/>\r
+ <Description>Openmano created</Description>\r
+ <Configuration>\r
+ <IpScopes>\r
+ <IpScope>\r
+ <IsInherited>true</IsInherited>\r
+ <Gateway>12.169.24.23</Gateway>\r
+ <Netmask>255.255.255.0</Netmask>\r
+ <Dns1>12.169.24.102</Dns1>\r
+ <DnsSuffix>corp.local</DnsSuffix>\r
+ <IsEnabled>true</IsEnabled>\r
+ <IpRanges>\r
+ <IpRange>\r
+ <StartAddress>12.169.241.115</StartAddress>\r
+ <EndAddress>12.169.241.150</EndAddress>\r
+ </IpRange></IpRanges></IpScope>\r
+ </IpScopes>\r
+ <FenceMode>bridged</FenceMode>\r
+ <RetainNetInfoAcrossDeployments>false</RetainNetInfoAcrossDeployments>\r
+ </Configuration>\r
+ <IsShared>false</IsShared>\r
+ </OrgVdcNetwork>"""\r
+\r
+create_network_xml_response = """<?xml version="1.0" encoding="UTF-8"?>\r
+ <OrgVdcNetwork xmlns="http://www.vmware.com/vcloud/v1.5" name="Test_network-25cb63aa-30e9-4de5-be76-1d6e00a2781a" id="urn:vcloud:network:df1956fa-da04-419e-a6a2-427b6f83788f" href="https://localhost/api/admin/network/df1956fa-da04-419e-a6a2-427b6f83788f" type="application/vnd.vmware.vcloud.orgVdcNetwork+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://localhost/api/v1.5/schema/master.xsd">\r
+ <Link rel="edit" href="https://localhost/api/admin/network/df1956fa-da04-419e-a6a2-427b6f83788f" type="application/vnd.vmware.vcloud.orgVdcNetwork+xml"/>\r
+ <Link rel="remove" href="https://localhost/api/admin/network/df1956fa-da04-419e-a6a2-427b6f83788f"/>\r
+ <Link rel="repair" href="https://localhost/api/admin/network/df1956fa-da04-419e-a6a2-427b6f83788f/action/reset"/>\r
+ <Link rel="up" href="https://localhost/api/admin/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69" type="application/vnd.vmware.admin.vdc+xml"/>\r
+ <Link rel="down" href="https://localhost/api/admin/network/df1956fa-da04-419e-a6a2-427b6f83788f/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>\r
+ <Link rel="down" href="https://localhost/api/admin/network/df1956fa-da04-419e-a6a2-427b6f83788f/allocatedAddresses/" type="application/vnd.vmware.vcloud.allocatedNetworkAddress+xml"/>\r
+ <Description>Openmano created</Description>\r
+ <Tasks>\r
+ <Task cancelRequested="false" expiryTime="2017-12-14T02:00:39.865-08:00" operation="Creating Network Test_network-25cb63aa-30e9-4de5-be76-1d6e00a2781a(df1956fa-da04-419e-a6a2-427b6f83788f)" operationName="networkCreateOrgVdcNetwork" serviceNamespace="com.vmware.vcloud" startTime="2017-09-15T02:00:39.865-07:00" status="queued" name="task" id="urn:vcloud:task:0600f592-42ce-4d58-85c0-212c569ba6e6" href="https://localhost/api/task/0600f592-42ce-4d58-85c0-212c569ba6e6" type="application/vnd.vmware.vcloud.task+xml">\r
+ <Owner href="https://localhost/api/admin/network/df1956fa-da04-419e-a6a2-427b6f83788f" name="Test_network-25cb63aa-30e9-4de5-be76-1d6e00a2781a" type="application/vnd.vmware.admin.network+xml"/>\r
+ <User href="https://localhost/api/admin/user/f49f28e0-7172-4b17-aaee-d171ce2b60da" name="administrator" type="application/vnd.vmware.admin.user+xml"/>\r
+ <Organization href="https://localhost/api/org/a93c9db9-7471-3192-8d09-a8f7eeda85f9" name="System" type="application/vnd.vmware.vcloud.org+xml"/>\r
+ <Details/>\r
+ </Task>\r
+ </Tasks>\r
+ <Configuration>\r
+ <IpScopes><IpScope>\r
+ <IsInherited>false</IsInherited>\r
+ <Gateway>12.16.113.1</Gateway>\r
+ <Netmask>255.255.255.0</Netmask>\r
+ <Dns1>12.16.113.2</Dns1>\r
+ <IsEnabled>true</IsEnabled>\r
+ <IpRanges><IpRange>\r
+ <StartAddress>12.168.113.3</StartAddress>\r
+ <EndAddress>12.168.113.52</EndAddress>\r
+ </IpRange></IpRanges>\r
+ </IpScope></IpScopes>\r
+ <ParentNetwork href="https://localhost/api/admin/network/19b01b42-c862-4d0f-bcbf-d053e7396fc0" name="" type="application/vnd.vmware.admin.network+xml"/>\r
+ <FenceMode>bridged</FenceMode>\r
+ <RetainNetInfoAcrossDeployments>false</RetainNetInfoAcrossDeployments>\r
+ </Configuration><IsShared>false</IsShared>\r
+ </OrgVdcNetwork>"""\r
+\r
+catalog1_xml_response = """<?xml version="1.0" encoding="UTF-8"?>\r
+<Catalog xmlns="http://www.vmware.com/vcloud/v1.5" name="Ubuntu-vm" id="urn:vcloud:catalog:d0a11b12-780e-4681-babb-2b1fd6693f62" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62" type="application/vnd.vmware.vcloud.catalog+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://localhost/api/v1.5/schema/master.xsd">\r
+<Link rel="up" href="https://localhost/api/org/2cb3dffb-5c51-4355-8406-28553ead28ac" type="application/vnd.vmware.vcloud.org+xml"/>\r
+<Link rel="down" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>\r
+<Link rel="add" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62/catalogItems" type="application/vnd.vmware.vcloud.catalogItem+xml"/>\r
+<Link rel="add" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62/action/upload" type="application/vnd.vmware.vcloud.media+xml"/>\r
+<Link rel="add" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62/action/upload" type="application/vnd.vmware.vcloud.uploadVAppTemplateParams+xml"/>\r
+<Link rel="copy" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62/action/copy" type="application/vnd.vmware.vcloud.copyOrMoveCatalogItemParams+xml"/>\r
+<Link rel="move" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62/action/move" type="application/vnd.vmware.vcloud.copyOrMoveCatalogItemParams+xml"/>\r
+<Link rel="add" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62/action/captureVApp" type="application/vnd.vmware.vcloud.captureVAppParams+xml"/>\r
+<Link rel="down" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62/controlAccess/" type="application/vnd.vmware.vcloud.controlAccess+xml"/>\r
+<Link rel="controlAccess" href="https://localhost/api/catalog/d0a11b12-780e-4681-babb-2b1fd6693f62/action/controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml"/> <Description>Ubuntu-vm</Description>\r
+<CatalogItems><CatalogItem href="https://localhost/api/catalogItem/04fc0041-8e40-4e37-b072-7dba3e1c6a30" id="04fc0041-8e40-4e37-b072-7dba3e1c6a30" name="Ubuntu-vm" type="application/vnd.vmware.vcloud.catalogItem+xml"/></CatalogItems><IsPublished>false</IsPublished><DateCreated>2017-03-17T03:17:11.293-07:00</DateCreated><VersionNumber>5</VersionNumber>\r
+</Catalog>"""\r
+\r
+catalog2_xml_response = """<?xml version="1.0" encoding="UTF-8"?>\r
+<Catalog xmlns="http://www.vmware.com/vcloud/v1.5" name="cirros" id="urn:vcloud:catalog:32ccb082-4a65-41f6-bcd6-38942e8a3829" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829" type="application/vnd.vmware.vcloud.catalog+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://localhost/api/v1.5/schema/master.xsd">\r
+<Link rel="up" href="https://localhost/api/org/2cb3dffb-5c51-4355-8406-28553ead28ac" type="application/vnd.vmware.vcloud.org+xml"/>\r
+<Link rel="down" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>\r
+<Link rel="add" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829/catalogItems" type="application/vnd.vmware.vcloud.catalogItem+xml"/>\r
+<Link rel="add" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829/action/upload" type="application/vnd.vmware.vcloud.media+xml"/>\r
+<Link rel="add" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829/action/upload" type="application/vnd.vmware.vcloud.uploadVAppTemplateParams+xml"/>\r
+<Link rel="copy" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829/action/copy" type="application/vnd.vmware.vcloud.copyOrMoveCatalogItemParams+xml"/>\r
+<Link rel="move" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829/action/move" type="application/vnd.vmware.vcloud.copyOrMoveCatalogItemParams+xml"/>\r
+<Link rel="add" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829/action/captureVApp" type="application/vnd.vmware.vcloud.captureVAppParams+xml"/>\r
+<Link rel="down" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829/controlAccess/" type="application/vnd.vmware.vcloud.controlAccess+xml"/>\r
+<Link rel="controlAccess" href="https://localhost/api/catalog/32ccb082-4a65-41f6-bcd6-38942e8a3829/action/controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml"/> <Description>cirros</Description>\r
+<CatalogItems><CatalogItem href="https://localhost/api/catalogItem/98316d41-e38c-40c2-ac28-5462e8aada8c" id="98316d41-e38c-40c2-ac28-5462e8aada8c" name="cirros" type="application/vnd.vmware.vcloud.catalogItem+xml"/></CatalogItems><IsPublished>false</IsPublished><DateCreated>2017-03-08T02:06:07.003-08:00</DateCreated><VersionNumber>5</VersionNumber>\r
+</Catalog>"""\r
+\r
+vapp_xml_response = """<?xml version="1.0" encoding="UTF-8"?>\r
+<VApp xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ovfDescriptorUploaded="true" deployed="true" status="4" name="Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa" id="urn:vcloud:vapp:4f6a9b49-e92d-4935-87a1-0e4dc9c3a069" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069" type="application/vnd.vmware.vcloud.vApp+xml" xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8023_1.1.0.xsd http://www.vmware.com/vcloud/v1.5 http://localhost/api/v1.5/schema/master.xsd http://www.vmware.com/schema/ovf http://www.vmware.com/schema/ovf http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd http://schemas.dmtf.org/ovf/environment/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8027_1.1.0.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_VirtualSystemSettingData.xsd">\r
+<Link rel="power:powerOff" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/power/action/powerOff"/>\r
+<Link rel="power:reboot" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/power/action/reboot"/>\r
+<Link rel="power:reset" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/power/action/reset"/>\r
+<Link rel="power:shutdown" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/power/action/shutdown"/>\r
+<Link rel="power:suspend" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/power/action/suspend"/>\r
+<Link rel="deploy" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/action/deploy" type="application/vnd.vmware.vcloud.deployVAppParams+xml"/>\r
+<Link rel="undeploy" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/action/undeploy" type="application/vnd.vmware.vcloud.undeployVAppParams+xml"/>\r
+<Link rel="down" href="https://localhost/api/network/9489a59a-0339-4151-9667-f5b90296c36d" name="External-Network-1074" type="application/vnd.vmware.vcloud.vAppNetwork+xml"/>\r
+<Link rel="down" href="https://localhost/api/network/379f083b-4057-4724-a128-ed5bc6672591" name="testing_T6nODiW4-68f68d93-0350-4d86-b40b-6e74dedf994d" type="application/vnd.vmware.vcloud.vAppNetwork+xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/controlAccess/" type="application/vnd.vmware.vcloud.controlAccess+xml"/>\r
+<Link rel="controlAccess" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/action/controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml"/>\r
+<Link rel="up" href="https://localhost/api/vdc/2584137f-6541-4c04-a2a2-e56bfca14c69" type="application/vnd.vmware.vcloud.vdc+xml"/>\r
+<Link rel="edit" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069" type="application/vnd.vmware.vcloud.vApp+xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/owner" type="application/vnd.vmware.vcloud.owner+xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>\r
+<Link rel="ovf" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/ovf" type="text/xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/productSections/" type="application/vnd.vmware.vcloud.productSections+xml"/>\r
+<Link rel="snapshot:create" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/action/createSnapshot" type="application/vnd.vmware.vcloud.createSnapshotParams+xml"/>\r
+<LeaseSettingsSection href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/leaseSettingsSection/" type="application/vnd.vmware.vcloud.leaseSettingsSection+xml" ovf:required="false">\r
+<ovf:Info>Lease settings section</ovf:Info>\r
+<Link rel="edit" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/leaseSettingsSection/" type="application/vnd.vmware.vcloud.leaseSettingsSection+xml"/> <DeploymentLeaseInSeconds>0</DeploymentLeaseInSeconds><StorageLeaseInSeconds>7776000</StorageLeaseInSeconds></LeaseSettingsSection>\r
+<ovf:StartupSection xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:type="application/vnd.vmware.vcloud.startupSection+xml" vcloud:href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/startupSection/"><ovf:Info>VApp startup section</ovf:Info>\r
+<ovf:Item ovf:id="Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa" ovf:order="0" ovf:startAction="powerOn" ovf:startDelay="0" ovf:stopAction="powerOff" ovf:stopDelay="0"/>\r
+<Link rel="edit" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/startupSection/" type="application/vnd.vmware.vcloud.startupSection+xml"/> </ovf:StartupSection><ovf:NetworkSection xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:type="application/vnd.vmware.vcloud.networkSection+xml" vcloud:href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/networkSection/"><ovf:Info>The list of logical networks</ovf:Info>\r
+<ovf:Network ovf:name="External-Network-1074"><ovf:Description>External-Network-1074</ovf:Description></ovf:Network>\r
+<ovf:Network ovf:name="testing_T6nODiW4-68f68d93-0350-4d86-b40b-6e74dedf994d"><ovf:Description/></ovf:Network></ovf:NetworkSection>\r
+<NetworkConfigSection href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/networkConfigSection/" type="application/vnd.vmware.vcloud.networkConfigSection+xml" ovf:required="false"><ovf:Info>The configuration parameters for logical networks</ovf:Info>\r
+<Link rel="edit" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/networkConfigSection/" type="application/vnd.vmware.vcloud.networkConfigSection+xml"/><NetworkConfig networkName="External-Network-1074"><Link rel="repair" href="https://localhost/api/admin/network/9489a59a-0339-4151-9667-f5b90296c36d/action/reset"/>\r
+<Description>External-Network-1074</Description><Configuration><IpScopes><IpScope><IsInherited>false</IsInherited><Gateway>192.168.254.1</Gateway><Netmask>255.255.255.0</Netmask>\r
+<IsEnabled>true</IsEnabled><IpRanges><IpRange><StartAddress>192.168.254.100</StartAddress><EndAddress>192.168.254.199</EndAddress></IpRange></IpRanges></IpScope></IpScopes>\r
+<FenceMode>isolated</FenceMode><RetainNetInfoAcrossDeployments>false</RetainNetInfoAcrossDeployments></Configuration><IsDeployed>true</IsDeployed></NetworkConfig>\r
+<NetworkConfig networkName="testing_T6nODiW4-68f68d93-0350-4d86-b40b-6e74dedf994d">\r
+<Link rel="repair" href="https://localhost/api/admin/network/379f083b-4057-4724-a128-ed5bc6672591/action/reset"/><Description/><Configuration><IpScopes><IpScope><IsInherited>true</IsInherited>\r
+<Gateway>192.169.241.253</Gateway><Netmask>255.255.255.0</Netmask><Dns1>192.169.241.102</Dns1><DnsSuffix>corp.local</DnsSuffix><IsEnabled>true</IsEnabled><IpRanges><IpRange>\r
+<StartAddress>192.169.241.115</StartAddress><EndAddress>192.169.241.150</EndAddress></IpRange></IpRanges></IpScope></IpScopes>\r
+<ParentNetwork href="https://localhost/api/admin/network/d4307ff7-0e34-4d41-aab0-4c231a045088" id="d4307ff7-0e34-4d41-aab0-4c231a045088" name="testing_T6nODiW4-68f68d93-0350-4d86-b40b-6e74dedf994d"/><FenceMode>bridged</FenceMode><RetainNetInfoAcrossDeployments>false</RetainNetInfoAcrossDeployments></Configuration>\r
+<IsDeployed>true</IsDeployed></NetworkConfig></NetworkConfigSection><SnapshotSection href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069/snapshotSection" type="application/vnd.vmware.vcloud.snapshotSection+xml" ovf:required="false"><ovf:Info>Snapshot information section</ovf:Info></SnapshotSection><DateCreated>2017-09-21T01:15:31.627-07:00</DateCreated><Owner type="application/vnd.vmware.vcloud.owner+xml">\r
+<User href="https://localhost/api/admin/user/f7b6beba-96db-4674-b187-675ed1873c8c" name="orgadmin" type="application/vnd.vmware.admin.user+xml"/>\r
+</Owner><InMaintenanceMode>false</InMaintenanceMode><Children>\r
+<Vm needsCustomization="false" nestedHypervisorEnabled="false" deployed="true" status="4" name="Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa" id="urn:vcloud:vm:47d12505-5968-4e16-95a7-18743edb0c8b" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b" type="application/vnd.vmware.vcloud.vm+xml">\r
+<Link rel="power:powerOff" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/power/action/powerOff"/>\r
+<Link rel="power:reboot" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/power/action/reboot"/>\r
+<Link rel="power:reset" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/power/action/reset"/>\r
+<Link rel="power:shutdown" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/power/action/shutdown"/>\r
+<Link rel="power:suspend" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/power/action/suspend"/>\r
+<Link rel="undeploy" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/action/undeploy" type="application/vnd.vmware.vcloud.undeployVAppParams+xml"/>\r
+<Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b" type="application/vnd.vmware.vcloud.vm+xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/metadata" type="application/vnd.vmware.vcloud.metadata+xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/productSections/" type="application/vnd.vmware.vcloud.productSections+xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/metrics/current" type="application/vnd.vmware.vcloud.metrics.currentUsageSpec+xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/metrics/historic" type="application/vnd.vmware.vcloud.metrics.historicUsageSpec+xml"/>\r
+<Link rel="metrics" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/metrics/current" type="application/vnd.vmware.vcloud.metrics.currentUsageSpec+xml"/>\r
+<Link rel="metrics" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/metrics/historic" type="application/vnd.vmware.vcloud.metrics.historicUsageSpec+xml"/>\r
+<Link rel="screen:thumbnail" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/screen"/>\r
+<Link rel="screen:acquireTicket" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/screen/action/acquireTicket"/>\r
+<Link rel="screen:acquireMksTicket" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/screen/action/acquireMksTicket" type="application/vnd.vmware.vcloud.mksTicket+xml"/>\r
+<Link rel="media:insertMedia" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/media/action/insertMedia" type="application/vnd.vmware.vcloud.mediaInsertOrEjectParams+xml"/>\r
+<Link rel="media:ejectMedia" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/media/action/ejectMedia" type="application/vnd.vmware.vcloud.mediaInsertOrEjectParams+xml"/>\r
+<Link rel="disk:attach" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/disk/action/attach" type="application/vnd.vmware.vcloud.diskAttachOrDetachParams+xml"/>\r
+<Link rel="disk:detach" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/disk/action/detach" type="application/vnd.vmware.vcloud.diskAttachOrDetachParams+xml"/>\r
+<Link rel="installVmwareTools" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/action/installVMwareTools"/>\r
+<Link rel="customizeAtNextPowerOn" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/action/customizeAtNextPowerOn"/>\r
+<Link rel="snapshot:create" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/action/createSnapshot" type="application/vnd.vmware.vcloud.createSnapshotParams+xml"/>\r
+<Link rel="reconfigureVm" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/action/reconfigureVm" name="Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa" type="application/vnd.vmware.vcloud.vm+xml"/>\r
+<Link rel="up" href="https://localhost/api/vApp/vapp-4f6a9b49-e92d-4935-87a1-0e4dc9c3a069" type="application/vnd.vmware.vcloud.vApp+xml"/><Description>Ubuntu-vm</Description> <ovf:VirtualHardwareSection xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" ovf:transport="" vcloud:type="application/vnd.vmware.vcloud.virtualHardwareSection+xml" vcloud:href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/"><ovf:Info>Virtual hardware requirements</ovf:Info><ovf:System><vssd:ElementName>Virtual Hardware Family</vssd:ElementName><vssd:InstanceID>0</vssd:InstanceID> <vssd:VirtualSystemIdentifier>Test1_vm-69a18104-8413-4cb8-bad7-b5afaec6f9fa</vssd:VirtualSystemIdentifier><vssd:VirtualSystemType>vmx-11</vssd:VirtualSystemType></ovf:System><ovf:Item> <rasd:Address>00:50:56:01:12:a2</rasd:Address><rasd:AddressOnParent>0</rasd:AddressOnParent> <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> <rasd:Connection vcloud:ipAddressingMode="DHCP" vcloud:ipAddress="12.19.21.20" vcloud:primaryNetworkConnection="true">testing_T6nODiW4-68f68d93-0350-4d86-b40b-6e74dedf994d</rasd:Connection> <rasd:Description>Vmxnet3 ethernet adapter on "testing_T6nODiW4-68f68d93-0350-4d86-b40b-6e74dedf994d"</rasd:Description> <rasd:ElementName>Network adapter 0</rasd:ElementName> <rasd:InstanceID>1</rasd:InstanceID> <rasd:ResourceSubType>VMXNET3</rasd:ResourceSubType> <rasd:ResourceType>10</rasd:ResourceType></ovf:Item><ovf:Item> <rasd:Address>0</rasd:Address> <rasd:Description>SCSI Controller</rasd:Description> <rasd:ElementName>SCSI Controller 0</rasd:ElementName> <rasd:InstanceID>2</rasd:InstanceID> <rasd:ResourceSubType>lsilogic</rasd:ResourceSubType> <rasd:ResourceType>6</rasd:ResourceType></ovf:Item><ovf:Item> <rasd:AddressOnParent>0</rasd:AddressOnParent> <rasd:Description>Hard disk</rasd:Description> <rasd:ElementName>Hard disk 1</rasd:ElementName> <rasd:HostResource vcloud:storageProfileHref="https://localhost/api/vdcStorageProfile/950701fb-2b8a-4808-80f1-27d1170a2bfc" vcloud:busType="6" vcloud:busSubType="lsilogic" vcloud:capacity="40960" vcloud:storageProfileOverrideVmDefault="false"/> <rasd:InstanceID>2000</rasd:InstanceID> <rasd:Parent>2</rasd:Parent> <rasd:ResourceType>17</rasd:ResourceType> <rasd:VirtualQuantity>42949672960</rasd:VirtualQuantity> <rasd:VirtualQuantityUnits>byte</rasd:VirtualQuantityUnits></ovf:Item><ovf:Item> <rasd:Address>0</rasd:Address> <rasd:Description>SATA Controller</rasd:Description> <rasd:ElementName>SATA Controller 0</rasd:ElementName> <rasd:InstanceID>3</rasd:InstanceID> <rasd:ResourceSubType>vmware.sata.ahci</rasd:ResourceSubType> <rasd:ResourceType>20</rasd:ResourceType></ovf:Item><ovf:Item> <rasd:AddressOnParent>0</rasd:AddressOnParent> <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> <rasd:Description>CD/DVD Drive</rasd:Description> <rasd:ElementName>CD/DVD Drive 1</rasd:ElementName> <rasd:HostResource/> <rasd:InstanceID>16000</rasd:InstanceID> <rasd:Parent>3</rasd:Parent> <rasd:ResourceType>15</rasd:ResourceType></ovf:Item><ovf:Item> <rasd:AddressOnParent>0</rasd:AddressOnParent> <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> <rasd:Description>Floppy Drive</rasd:Description> <rasd:ElementName>Floppy Drive 1</rasd:ElementName> <rasd:HostResource/> <rasd:InstanceID>8000</rasd:InstanceID> <rasd:ResourceType>14</rasd:ResourceType></ovf:Item><ovf:Item vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" vcloud:href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/cpu"> <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> <rasd:Description>Number of Virtual CPUs</rasd:Description> <rasd:ElementName>1 virtual CPU(s)</rasd:ElementName> <rasd:InstanceID>4</rasd:InstanceID> <rasd:Reservation>0</rasd:Reservation> <rasd:ResourceType>3</rasd:ResourceType> <rasd:VirtualQuantity>1</rasd:VirtualQuantity> <rasd:Weight>0</rasd:Weight> <vmw:CoresPerSocket ovf:required="false">1</vmw:CoresPerSocket> <Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/cpu" type="application/vnd.vmware.vcloud.rasdItem+xml"/></ovf:Item><ovf:Item vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml" vcloud:href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/memory"> <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> <rasd:Description>Memory Size</rasd:Description> <rasd:ElementName>1024 MB of memory</rasd:ElementName> <rasd:InstanceID>5</rasd:InstanceID> <rasd:Reservation>0</rasd:Reservation> <rasd:ResourceType>4</rasd:ResourceType> <rasd:VirtualQuantity>1024</rasd:VirtualQuantity> <rasd:Weight>0</rasd:Weight> <Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/memory" type="application/vnd.vmware.vcloud.rasdItem+xml"/></ovf:Item><Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/" type="application/vnd.vmware.vcloud.virtualHardwareSection+xml"/><Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/cpu" type="application/vnd.vmware.vcloud.rasdItem+xml"/>\r
+<Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/cpu" type="application/vnd.vmware.vcloud.rasdItem+xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/memory" type="application/vnd.vmware.vcloud.rasdItem+xml"/>\r
+<Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/memory" type="application/vnd.vmware.vcloud.rasdItem+xml"/>\r
+<Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/disks" type="application/vnd.vmware.vcloud.rasdItemsList+xml"/>\r
+<Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/disks" type="application/vnd.vmware.vcloud.rasdItemsList+xml"/><Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/media" type="application/vnd.vmware.vcloud.rasdItemsList+xml"/><Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/networkCards" type="application/vnd.vmware.vcloud.rasdItemsList+xml"/><Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/networkCards" type="application/vnd.vmware.vcloud.rasdItemsList+xml"/><Link rel="down" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/serialPorts" type="application/vnd.vmware.vcloud.rasdItemsList+xml"/><Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/virtualHardwareSection/serialPorts" type="application/vnd.vmware.vcloud.rasdItemsList+xml"/></ovf:VirtualHardwareSection><ovf:OperatingSystemSection xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" ovf:id="94" vcloud:type="application/vnd.vmware.vcloud.operatingSystemSection+xml" vmw:osType="ubuntu64Guest" vcloud:href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/operatingSystemSection/"><ovf:Info>Specifies the operating system installed</ovf:Info><ovf:Description>Ubuntu Linux (64-bit)</ovf:Description><Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/operatingSystemSection/" type="application/vnd.vmware.vcloud.operatingSystemSection+xml"/></ovf:OperatingSystemSection><NetworkConnectionSection href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/networkConnectionSection/" type="application/vnd.vmware.vcloud.networkConnectionSection+xml" ovf:required="false"><ovf:Info>Specifies the available VM network connections</ovf:Info><PrimaryNetworkConnectionIndex>0</PrimaryNetworkConnectionIndex><NetworkConnection needsCustomization="false" network="testing_T6nODiW4-68f68d93-0350-4d86-b40b-6e74dedf994d"> <NetworkConnectionIndex>0</NetworkConnectionIndex> <IpAddress>12.19.21.20</IpAddress> <IsConnected>true</IsConnected> <MACAddress>00:50:56:01:12:a2</MACAddress> <IpAddressAllocationMode>DHCP</IpAddressAllocationMode></NetworkConnection><Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/networkConnectionSection/" type="application/vnd.vmware.vcloud.networkConnectionSection+xml"/></NetworkConnectionSection><GuestCustomizationSection href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/guestCustomizationSection/" type="application/vnd.vmware.vcloud.guestCustomizationSection+xml" ovf:required="false"><ovf:Info>Specifies Guest OS Customization Settings</ovf:Info><Enabled>true</Enabled><ChangeSid>false</ChangeSid><VirtualMachineId>47d12505-5968-4e16-95a7-18743edb0c8b</VirtualMachineId><JoinDomainEnabled>false</JoinDomainEnabled><UseOrgSettings>false</UseOrgSettings><AdminPasswordEnabled>false</AdminPasswordEnabled><AdminPasswordAuto>true</AdminPasswordAuto><AdminAutoLogonEnabled>false</AdminAutoLogonEnabled><AdminAutoLogonCount>0</AdminAutoLogonCount><ResetPasswordRequired>false</ResetPasswordRequired><ComputerName>Ubuntu-vm-001</ComputerName><Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/guestCustomizationSection/" type="application/vnd.vmware.vcloud.guestCustomizationSection+xml"/></GuestCustomizationSection><RuntimeInfoSection xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:type="application/vnd.vmware.vcloud.virtualHardwareSection+xml" vcloud:href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/runtimeInfoSection"><ovf:Info>Specifies Runtime info</ovf:Info><VMWareTools version="2147483647"/></RuntimeInfoSection><SnapshotSection href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/snapshotSection" type="application/vnd.vmware.vcloud.snapshotSection+xml" ovf:required="false"><ovf:Info>Snapshot information section</ovf:Info></SnapshotSection><DateCreated>2017-09-21T01:15:53.863-07:00</DateCreated><VAppScopedLocalId>Ubuntu-vm</VAppScopedLocalId><ovfenv:Environment xmlns:ns11="http://www.vmware.com/schema/ovfenv" ovfenv:id="" ns11:vCenterId="vm-7833"><ovfenv:PlatformSection> <ovfenv:Kind>VMware ESXi</ovfenv:Kind> <ovfenv:Version>6.0.0</ovfenv:Version> <ovfenv:Vendor>VMware, Inc.</ovfenv:Vendor> <ovfenv:Locale>en</ovfenv:Locale></ovfenv:PlatformSection><ovfenv:PropertySection> <ovfenv:Property ovfenv:key="vCloud_UseSysPrep" ovfenv:value="None"/> <ovfenv:Property ovfenv:key="vCloud_bitMask" ovfenv:value="1"/> <ovfenv:Property ovfenv:key="vCloud_bootproto_0" ovfenv:value="dhcp"/> <ovfenv:Property ovfenv:key="vCloud_computerName" ovfenv:value="Ubuntu-vm-001"/> <ovfenv:Property ovfenv:key="vCloud_macaddr_0" ovfenv:value="00:50:56:01:12:a2"/> <ovfenv:Property ovfenv:key="vCloud_markerid" ovfenv:value="c743cbe8-136e-4cf8-9e42-b291646b8058"/> <ovfenv:Property ovfenv:key="vCloud_numnics" ovfenv:value="1"/> <ovfenv:Property ovfenv:key="vCloud_primaryNic" ovfenv:value="0"/> <ovfenv:Property ovfenv:key="vCloud_reconfigToken" ovfenv:value="246124151"/> <ovfenv:Property ovfenv:key="vCloud_resetPassword" ovfenv:value="0"/></ovfenv:PropertySection><ve:EthernetAdapterSection xmlns:ve="http://www.vmware.com/schema/ovfenv" xmlns="http://schemas.dmtf.org/ovf/environment/1" xmlns:oe="http://schemas.dmtf.org/ovf/environment/1"> <ve:Adapter ve:mac="00:50:56:01:12:a2" ve:network="DPG-MGMT-3151" ve:unitNumber="7"/></ve:EthernetAdapterSection></ovfenv:Environment><VmCapabilities href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/vmCapabilities/" type="application/vnd.vmware.vcloud.vmCapabilitiesSection+xml"><Link rel="edit" href="https://localhost/api/vApp/vm-47d12505-5968-4e16-95a7-18743edb0c8b/vmCapabilities/" type="application/vnd.vmware.vcloud.vmCapabilitiesSection+xml"/><MemoryHotAddEnabled>false</MemoryHotAddEnabled><CpuHotAddEnabled>false</CpuHotAddEnabled></VmCapabilities><StorageProfile href="https://localhost/api/vdcStorageProfile/950701fb-2b8a-4808-80f1-27d1170a2bfc" name="*" type="application/vnd.vmware.vcloud.vdcStorageProfile+xml"/></Vm></Children></VApp>"""\r
+\r
+task_xml = """<?xml version="1.0" encoding="UTF-8"?>\r
+ <Task xmlns="http://www.vmware.com/vcloud/v1.5" cancelRequested="false" expiryTime="2017-12-22T23:18:23.040-08:00" operation="Powering Off Virtual Application Test1_vm-f370dafc-4aad-4415-bad9-68509dda67c9(f26ebf0a-f675-4622-83a6-64c6401769ac)" operationName="vappPowerOff" serviceNamespace="com.vmware.vcloud" startTime="2017-09-23T23:18:23.040-07:00" status="queued" name="task" id="urn:vcloud:task:26975b6e-310e-4ed9-914e-ba7051eaabcb" href="https://localhost/api/task/26975b6e-310e-4ed9-914e-ba7051eaabcb" type="application/vnd.vmware.vcloud.task+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://localhost/api/v1.5/schema/master.xsd"><Owner href="https://localhost/api/vApp/vapp-f26ebf0a-f675-4622-83a6-64c6401769ac" name="Test1_vm-f370dafc-4aad-4415-bad9-68509dda67c9" type="application/vnd.vmware.vcloud.vApp+xml"/><User href="https://localhost/api/admin/user/f7b6beba-96db-4674-b187-675ed1873c8c" name="orgadmin" type="application/vnd.vmware.admin.user+xml"/><Organization href="https://localhost/api/org/2cb3dffb-5c51-4355-8406-28553ead28ac" name="Org3" type="application/vnd.vmware.vcloud.org+xml"/><Details/></Task>"""\r
networks = self.vca.get_networks(vdc.get_name())
filter_dict = {}
+ if not networks:
+ vimconn.vimconnNotFoundException("Network {} not found".format(net_id))
+
for network in networks:
vdc_network_id = network.get_id().split(":")
if len(vdc_network_id) == 4 and vdc_network_id[3] == net_id:
filter_dict["type"] = "bridge"
self.logger.debug("Returning {}".format(filter_dict))
return filter_dict
- except:
+ else:
+ raise vimconn.vimconnNotFoundException("Network {} not found".format(net_id))
+
+ except Exception as e:
self.logger.debug("Error in get_network")
self.logger.debug(traceback.format_exc())
+ if isinstance(e, vimconn.vimconnException):
+ raise
+ else:
+ raise vimconn.vimconnNotFoundException("Failed : Network not found {} ".format(e))
return filter_dict