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
13 from snaps.openstack.create_image import OpenStackImage
14 from snaps.openstack.create_instance import OpenStackVmInstance, \
16 from snaps.openstack.create_keypairs import OpenStackKeypair, KeypairSettings
17 from snaps.openstack.create_network import OpenStackNetwork, NetworkSettings, \
18 SubnetSettings, PortSettings
19 from snaps.openstack.create_router import OpenStackRouter, RouterSettings
20 from snaps.openstack.create_security_group import OpenStackSecurityGroup, \
22 from snaps.openstack.os_credentials import OSCreds
24 from functest.core.testcase import TestCase
25 from functest.opnfv_tests.openstack.vping import vping_userdata, vping_ssh
28 class VPingUserdataTesting(unittest.TestCase):
30 Ensures the VPingUserdata class can run in Functest. This test does not
31 actually connect with an OpenStack pod.
35 self.os_creds = OSCreds(
36 username='user', password='pass',
37 auth_url='http://foo.com:5000/v3', project_name='bar')
39 self.vping_userdata = vping_userdata.VPingUserdata(
40 os_creds=self.os_creds)
42 @mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
43 @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
44 'path.exists', return_value=True)
45 @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
47 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
48 'get_port_ip', return_value='10.0.0.1')
49 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
50 'vm_active', return_value=True)
51 def test_vping_userdata(self, deploy_vm, path_exists, create_flavor,
52 get_port_ip, vm_active):
53 with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
54 return_value=OpenStackImage(self.os_creds, None)), \
55 mock.patch('snaps.openstack.utils.deploy_utils.create_network',
56 return_value=OpenStackNetwork(
57 self.os_creds, NetworkSettings(name='foo'))), \
58 mock.patch('snaps.openstack.utils.deploy_utils.'
60 return_value=OpenStackVmInstance(
63 name='foo', flavor='bar',
64 port_settings=[PortSettings(
65 name='foo', network_name='bar')]),
67 mock.patch('snaps.openstack.create_instance.'
68 'OpenStackVmInstance.get_console_output',
69 return_value='vPing OK'):
70 self.assertEquals(TestCase.EX_OK, self.vping_userdata.run())
73 class VPingSSHTesting(unittest.TestCase):
75 Ensures the VPingUserdata class can run in Functest. This test does not
76 actually connect with an OpenStack pod.
80 self.os_creds = OSCreds(
81 username='user', password='pass',
82 auth_url='http://foo.com:5000/v3', project_name='bar')
84 self.vping_ssh = vping_ssh.VPingSSH(
85 os_creds=self.os_creds)
87 @mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
88 @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
89 'path.exists', return_value=True)
90 @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
92 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
93 'get_port_ip', return_value='10.0.0.1')
94 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
95 'vm_active', return_value=True)
96 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
97 'vm_ssh_active', return_value=True)
98 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
99 'ssh_client', return_value=True)
100 @mock.patch('scp.SCPClient')
101 @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.'
102 'VPingSSH._transfer_ping_script', return_value=True)
103 @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.'
104 'VPingSSH._do_vping_ssh', return_value=TestCase.EX_OK)
105 @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
106 'get_ext_net_name', return_value='foo')
107 def test_vping_ssh(self, create_vm, path_exists,
108 flavor_create, get_port_ip, vm_active, ssh_active,
109 ssh_client, scp_client, trans_script, do_vping_ssh,
111 os_vm_inst = mock.MagicMock(name='get_console_output')
112 os_vm_inst.get_console_output.return_value = 'vPing OK'
113 ssh_client = mock.MagicMock(name='get_transport')
114 ssh_client.get_transport.return_value = None
115 scp_client = mock.MagicMock(name='put')
116 scp_client.put.return_value = None
118 with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
119 return_value=OpenStackImage(self.os_creds, None)), \
120 mock.patch('snaps.openstack.utils.deploy_utils.create_network',
121 return_value=OpenStackNetwork(
128 cidr='10.0.0.1/24')]))), \
129 mock.patch('snaps.openstack.utils.deploy_utils.'
130 'create_vm_instance',
131 return_value=OpenStackVmInstance(
134 name='foo', flavor='bar',
135 port_settings=[PortSettings(
136 name='foo', network_name='bar')]),
138 mock.patch('snaps.openstack.utils.deploy_utils.create_keypair',
139 return_value=OpenStackKeypair(
140 self.os_creds, KeypairSettings(name='foo'))), \
141 mock.patch('snaps.openstack.utils.deploy_utils.create_router',
142 return_value=OpenStackRouter(
143 self.os_creds, RouterSettings(name='foo'))), \
144 mock.patch('snaps.openstack.utils.deploy_utils.'
145 'create_security_group',
146 return_value=OpenStackSecurityGroup(
148 SecurityGroupSettings(name='foo'))), \
149 mock.patch('snaps.openstack.create_instance.'
150 'OpenStackVmInstance.'
151 'get_vm_inst', return_value=os_vm_inst), \
152 mock.patch('snaps.openstack.create_instance.'
153 'OpenStackVmInstance.'
154 'ssh_client', return_value=ssh_client):
155 self.assertEquals(TestCase.EX_OK, self.vping_ssh.run())