How to use _assert_exec_called_with method in tempest

Best Python code snippet using tempest_python

test_remote_client.py

Source:test_remote_client.py Github

copy

Full Screen

...42 self.ssh_mock.mock.exec_command.return_value = free_output43 self.assertEqual(self.conn.get_ram_size_in_mb(), '48294')44 def test_write_to_console_regular_str(self):45 self.conn.write_to_console('test')46 self._assert_exec_called_with(47 'sudo sh -c "echo \\"test\\" >/dev/console"')48 def _test_write_to_console_helper(self, message, expected_call):49 self.conn.write_to_console(message)50 self._assert_exec_called_with(expected_call)51 def test_write_to_console_special_chars(self):52 self._test_write_to_console_helper(53 '\`',54 'sudo sh -c "echo \\"\\\\\\`\\" >/dev/console"')55 self.conn.write_to_console('$')56 self._assert_exec_called_with(57 'sudo sh -c "echo \\"\\\\$\\" >/dev/console"')58 # NOTE(maurosr): The tests below end up closer to an output format59 # assurance than a test since it's basically using comand_exec to format60 # the information using gnu/linux tools.61 def _assert_exec_called_with(self, cmd):62 cmd = "set -eu -o pipefail; PATH=$PATH:/sbin; " + cmd63 self.ssh_mock.mock.exec_command.assert_called_with(cmd)64 def test_get_number_of_vcpus(self):65 self.ssh_mock.mock.exec_command.return_value = '16'66 self.assertEqual(self.conn.get_number_of_vcpus(), 16)67 self._assert_exec_called_with('grep -c ^processor /proc/cpuinfo')68 def test_get_partitions(self):69 proc_partitions = """major minor #blocks name708 0 1048576 vda"""71 self.ssh_mock.mock.exec_command.return_value = proc_partitions72 self.assertEqual(self.conn.get_partitions(), proc_partitions)73 self._assert_exec_called_with('cat /proc/partitions')74 def test_get_boot_time(self):75 booted_at = 1000076 uptime_sec = 5000.0277 self.ssh_mock.mock.exec_command.return_value = uptime_sec78 self.useFixture(mockpatch.PatchObject(79 time, 'time', return_value=booted_at + uptime_sec))80 self.assertEqual(self.conn.get_boot_time(),81 time.localtime(booted_at))82 self._assert_exec_called_with('cut -f1 -d. /proc/uptime')83 def test_ping_host(self):84 ping_response = """PING localhost (127.0.0.1) 70(98) bytes of data.8578 bytes from localhost (127.0.0.1): icmp_req=1 ttl=64 time=0.048 ms8678 bytes from localhost (127.0.0.1): icmp_req=2 ttl=64 time=0.048 ms87--- localhost ping statistics ---882 packets transmitted, 2 received, 0% packet loss, time 0ms89rtt min/avg/max/mdev = 0.048/0.048/0.048/0.000 ms"""90 self.ssh_mock.mock.exec_command.return_value = ping_response91 self.assertEqual(self.conn.ping_host('127.0.0.1', count=2, size=70),92 ping_response)93 self._assert_exec_called_with('ping -c2 -w2 -s70 127.0.0.1')94 def test_get_mac_address(self):95 macs = """0a:0b:0c:0d:0e:0f96a0:b0:c0:d0:e0:f0"""97 self.ssh_mock.mock.exec_command.return_value = macs98 self.assertEqual(self.conn.get_mac_address(), macs)99 self._assert_exec_called_with(100 "ip addr | awk '/ether/ {print $2}'")101 def test_get_ip_list(self):102 ips = """1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue103 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00104 inet 127.0.0.1/8 scope host lo105 inet6 ::1/128 scope host106 valid_lft forever preferred_lft forever1072: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000108 link/ether fa:16:3e:6e:26:3b brd ff:ff:ff:ff:ff:ff109 inet 10.0.0.4/24 brd 10.0.0.255 scope global eth0110 inet6 fd55:faaf:e1ab:3d9:f816:3eff:fe6e:263b/64 scope global dynamic111 valid_lft 2591936sec preferred_lft 604736sec112 inet6 fe80::f816:3eff:fe6e:263b/64 scope link113 valid_lft forever preferred_lft forever"""114 self.ssh_mock.mock.exec_command.return_value = ips115 self.assertEqual(self.conn.get_ip_list(), ips)116 self._assert_exec_called_with('ip address')117 def test_assign_static_ip(self):118 self.ssh_mock.mock.exec_command.return_value = ''119 ip = '10.0.0.2'120 nic = 'eth0'121 self.assertEqual(self.conn.assign_static_ip(nic, ip), '')122 self._assert_exec_called_with(123 "sudo ip addr add %s/%s dev %s" % (ip, '28', nic))124 def test_set_nic_state(self):125 nic = 'eth0'126 self.conn.set_nic_state(nic)127 self._assert_exec_called_with(128 'sudo ip link set %s up' % nic)129 self.conn.set_nic_state(nic, "down")130 self._assert_exec_called_with(...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful