1 # Copyright (c) 2017 Cable Television Laboratories, Inc. and others.
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # pylint: disable=missing-docstring
15 from snaps.config.keypair import KeypairConfig
16 from snaps.config.network import NetworkConfig, PortConfig, SubnetConfig
17 from snaps.config.router import RouterConfig
18 from snaps.config.security_group import SecurityGroupConfig
19 from snaps.config.vm_inst import VmInstanceConfig
21 from snaps.openstack.create_image import OpenStackImage
22 from snaps.openstack.create_instance import OpenStackVmInstance
23 from snaps.openstack.create_keypairs import OpenStackKeypair
24 from snaps.openstack.create_network import OpenStackNetwork
25 from snaps.openstack.create_router import OpenStackRouter
26 from snaps.openstack.create_security_group import OpenStackSecurityGroup
28 from snaps.openstack.os_credentials import OSCreds
30 from functest.core.testcase import TestCase
31 from functest.opnfv_tests.openstack.vping import vping_userdata, vping_ssh
34 class VPingUserdataTesting(unittest.TestCase):
36 Ensures the VPingUserdata class can run in Functest. This test does not
37 actually connect with an OpenStack pod.
41 self.os_creds = OSCreds(
42 username='user', password='pass',
43 auth_url='http://foo.com:5000/v3', project_name='bar')
45 self.vping_userdata = vping_userdata.VPingUserdata(
46 os_creds=self.os_creds)
48 @mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
49 @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
50 'path.exists', return_value=True)
51 @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
53 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
54 'get_port_ip', return_value='10.0.0.1')
55 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
56 'vm_active', return_value=True)
57 def test_vping_userdata(self, deploy_vm, path_exists, create_flavor,
58 get_port_ip, vm_active):
59 with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
60 return_value=OpenStackImage(self.os_creds, None)), \
61 mock.patch('snaps.openstack.utils.deploy_utils.create_network',
62 return_value=OpenStackNetwork(
63 self.os_creds, NetworkConfig(name='foo'))), \
64 mock.patch('snaps.openstack.utils.deploy_utils.'
66 return_value=OpenStackVmInstance(
69 name='foo', flavor='bar',
70 port_settings=[PortConfig(
71 name='foo', network_name='bar')]),
73 mock.patch('snaps.openstack.create_instance.'
74 'OpenStackVmInstance.get_console_output',
75 return_value='vPing OK'):
76 self.assertEquals(TestCase.EX_OK, self.vping_userdata.run())
79 class VPingSSHTesting(unittest.TestCase):
81 Ensures the VPingUserdata class can run in Functest. This test does not
82 actually connect with an OpenStack pod.
86 self.os_creds = OSCreds(
87 username='user', password='pass',
88 auth_url='http://foo.com:5000/v3', project_name='bar')
90 self.vping_ssh = vping_ssh.VPingSSH(
91 os_creds=self.os_creds)
93 @mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
94 @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
95 'path.exists', return_value=True)
96 @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
98 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
99 'get_port_ip', return_value='10.0.0.1')
100 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
101 'vm_active', return_value=True)
102 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
103 'vm_ssh_active', return_value=True)
104 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
105 'ssh_client', return_value=True)
106 @mock.patch('scp.SCPClient')
107 @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.'
108 'VPingSSH._transfer_ping_script', return_value=True)
109 @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.'
110 'VPingSSH._do_vping_ssh', return_value=TestCase.EX_OK)
111 @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
112 'get_ext_net_name', return_value='foo')
113 def test_vping_ssh(self, create_vm, path_exists,
114 flavor_create, get_port_ip, vm_active, ssh_active,
115 ssh_client, scp_client, trans_script, do_vping_ssh,
117 os_vm_inst = mock.MagicMock(name='get_console_output')
118 os_vm_inst.get_console_output.return_value = 'vPing OK'
119 ssh_client = mock.MagicMock(name='get_transport')
120 ssh_client.get_transport.return_value = None
121 scp_client = mock.MagicMock(name='put')
122 scp_client.put.return_value = None
124 with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
125 return_value=OpenStackImage(self.os_creds, None)), \
126 mock.patch('snaps.openstack.utils.deploy_utils.create_network',
127 return_value=OpenStackNetwork(
134 cidr='10.0.0.1/24')]))), \
135 mock.patch('snaps.openstack.utils.deploy_utils.'
136 'create_vm_instance',
137 return_value=OpenStackVmInstance(
140 name='foo', flavor='bar',
141 port_settings=[PortConfig(
142 name='foo', network_name='bar')]),
144 mock.patch('snaps.openstack.utils.deploy_utils.create_keypair',
145 return_value=OpenStackKeypair(
146 self.os_creds, KeypairConfig(name='foo'))), \
147 mock.patch('snaps.openstack.utils.deploy_utils.create_router',
148 return_value=OpenStackRouter(
149 self.os_creds, RouterConfig(name='foo'))), \
150 mock.patch('snaps.openstack.utils.deploy_utils.'
151 'create_security_group',
152 return_value=OpenStackSecurityGroup(
154 SecurityGroupConfig(name='foo'))), \
155 mock.patch('snaps.openstack.create_instance.'
156 'OpenStackVmInstance.'
157 'get_vm_inst', return_value=os_vm_inst), \
158 mock.patch('snaps.openstack.create_instance.'
159 'OpenStackVmInstance.'
160 'ssh_client', return_value=ssh_client):
161 self.assertEquals(TestCase.EX_OK, self.vping_ssh.run())