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 os_vm_inst = mock.MagicMock(name='get_console_output')
54 os_vm_inst.get_console_output.return_value = 'vPing OK'
55 with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
56 return_value=OpenStackImage(self.os_creds, None)), \
57 mock.patch('snaps.openstack.utils.deploy_utils.create_network',
58 return_value=OpenStackNetwork(
59 self.os_creds, NetworkSettings(name='foo'))), \
60 mock.patch('snaps.openstack.utils.deploy_utils.'
62 return_value=OpenStackVmInstance(
65 name='foo', flavor='bar',
66 port_settings=[PortSettings(
67 name='foo', network_name='bar')]),
69 mock.patch('snaps.openstack.create_instance.'
70 'OpenStackVmInstance.get_os_vm_server_obj',
71 return_value=os_vm_inst):
72 self.assertEquals(TestCase.EX_OK, self.vping_userdata.run())
75 class VPingSSHTesting(unittest.TestCase):
77 Ensures the VPingUserdata class can run in Functest. This test does not
78 actually connect with an OpenStack pod.
82 self.os_creds = OSCreds(
83 username='user', password='pass',
84 auth_url='http://foo.com:5000/v3', project_name='bar')
86 self.vping_ssh = vping_ssh.VPingSSH(
87 os_creds=self.os_creds)
89 @mock.patch('snaps.openstack.utils.deploy_utils.create_vm_instance')
90 @mock.patch('functest.opnfv_tests.openstack.vping.vping_base.os.'
91 'path.exists', return_value=True)
92 @mock.patch('snaps.openstack.create_flavor.OpenStackFlavor.create',
94 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
95 'get_port_ip', return_value='10.0.0.1')
96 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
97 'vm_active', return_value=True)
98 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
99 'vm_ssh_active', return_value=True)
100 @mock.patch('snaps.openstack.create_instance.OpenStackVmInstance.'
101 'ssh_client', return_value=True)
102 @mock.patch('scp.SCPClient')
103 @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.'
104 'VPingSSH._transfer_ping_script', return_value=True)
105 @mock.patch('functest.opnfv_tests.openstack.vping.vping_ssh.'
106 'VPingSSH._do_vping_ssh', return_value=TestCase.EX_OK)
107 @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
108 'get_ext_net_name', return_value='foo')
109 def test_vping_ssh(self, create_vm, path_exists,
110 flavor_create, get_port_ip, vm_active, ssh_active,
111 ssh_client, scp_client, trans_script, do_vping_ssh,
113 os_vm_inst = mock.MagicMock(name='get_console_output')
114 os_vm_inst.get_console_output.return_value = 'vPing OK'
115 ssh_client = mock.MagicMock(name='get_transport')
116 ssh_client.get_transport.return_value = None
117 scp_client = mock.MagicMock(name='put')
118 scp_client.put.return_value = None
120 with mock.patch('snaps.openstack.utils.deploy_utils.create_image',
121 return_value=OpenStackImage(self.os_creds, None)), \
122 mock.patch('snaps.openstack.utils.deploy_utils.create_network',
123 return_value=OpenStackNetwork(
130 cidr='10.0.0.1/24')]))), \
131 mock.patch('snaps.openstack.utils.deploy_utils.'
132 'create_vm_instance',
133 return_value=OpenStackVmInstance(
136 name='foo', flavor='bar',
137 port_settings=[PortSettings(
138 name='foo', network_name='bar')]),
140 mock.patch('snaps.openstack.utils.deploy_utils.create_keypair',
141 return_value=OpenStackKeypair(
142 self.os_creds, KeypairSettings(name='foo'))), \
143 mock.patch('snaps.openstack.utils.deploy_utils.create_router',
144 return_value=OpenStackRouter(
145 self.os_creds, RouterSettings(name='foo'))), \
146 mock.patch('snaps.openstack.utils.deploy_utils.'
147 'create_security_group',
148 return_value=OpenStackSecurityGroup(
150 SecurityGroupSettings(name='foo'))), \
151 mock.patch('snaps.openstack.create_instance.'
152 'OpenStackVmInstance.'
153 'get_vm_inst', return_value=os_vm_inst), \
154 mock.patch('snaps.openstack.create_instance.'
155 'OpenStackVmInstance.'
156 'ssh_client', return_value=ssh_client):
157 self.assertEquals(TestCase.EX_OK, self.vping_ssh.run())