def configure_network(self, body): """ Calls the appropriate configure network method based on the OS type Example: @{r}= RG Configure Networks | <config> <config> is a dictionary and the supported key-value pairs are available in the respective functions. :param dict body: Key-value pairs containing network configuration :return list: List of network configuration status """ if not body.get('host'): log.info('Target system information is required') raise AssertionError('Host information dictionary is missing.') t = body.get('host').get('os', None) if t is None: log.info('Operating System type is required') raise AssertionError('Operating system type attribute missing') if "redhat" in t.lower() or "red hat" in t.lower() or \ "rhel" in t.lower(): return RedHatNetConfig().configure_network(body) elif "vmware" in t.lower() or "esx" in t.lower(): return VMwareNetConfig().configure_network(body) else: log.info('{} not supported'.format(body['host']['os'])) raise AssertionError('OS type not supported')
def test_invalid_host(self): """ Verify failure when there are no target system information :return: """ var = {"host": dict(), "config": rhel_conf['config']} r = RedHatNetConfig().configure_network(var) self.assertListEqual(r, list(), "Excepted emtpy results")
def test_missing_modules(self, cmd): """ Failure when modules are missing :param cmd: Handle to mock method _remote_cmd :return: """ var = {"host": redhat_host, "config": deepcopy(rhel_conf['config'][0])} r = RedHatNetConfig().configure_network(var) self.assertListEqual(r, list(), "Excepted emtpy results")
def test_missing_config(self): """ Verify network configuration fails due to missing config parameter :return: """ var = {"host": redhat_host, "config": []} r = RedHatNetConfig().configure_network(var) self.assertListEqual(r, list(), "Excepted empty results")
def test_missing_nmcli(self, cmd): """ Failure when 'nmcli' utility is not available :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True, False] var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][0])]} r = RedHatNetConfig().configure_network(var) self.assertListEqual(r, list(), "Excepted emtpy results")
def test_bond_network_fail(self, cmd): """ Failure during VLAN network creation :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 3 + [False] + [True] * 5 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][2])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], 'bond0.0') self.assertEquals(r[0]['status'], 'Fail')
def test_bond_slave_port_fail(self, cmd): """ Failure in creating bond master :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 5 + [False] + [True] * 3 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][2])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[1]['ports'], var['config'][0]['ports'][0]) self.assertEquals(r[1]['status'], 'Fail')
def test_pass_port_config(self, cmd): """ Verify the result when there is a pass :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True, True, 'eth1', True, True] var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][0])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], 'eth1') self.assertEquals(r[0]['status'], 'Pass')
def test_fail_port_config(self, cmd): """ Failure when the nmcli fails to configure the port :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True, True, 'eth1', False, True] var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][0])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], 'eth1') self.assertEquals(r[0]['status'], 'Fail')
def test_invalid_device_name(self, cmd): """ Failure when the MAC address is invalid :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True, True, False, False, True] var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][0])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], var['config'][0]['ports']) self.assertEquals(r[0]['status'], 'Fail')
def test_bond_network_pass(self, cmd): """ Verify the results on success :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 9 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][2])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], 'bond0.0') self.assertEquals(r[0]['status'], 'Pass')
def test_team_cfg_port_fail(self, cmd): """ Failure to configure team port :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 8 + [False] + [True] * 2 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][4])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[2]['ports'], var['config'][0]['ports'][1]) self.assertEquals(r[2]['status'], 'Fail')
def test_incorrect_port_number(self, cmd): """ Failure when there is an incorrect number of ports :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 3 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][0])]} var['config'][0]['ports'].append('gg:kk:zz:yy') r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], var['config'][0]['ports']) self.assertEquals(r[0]['status'], 'Fail')
def test_missing_network_type(self, cmd): """ Failure when type is unavailable in config :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 3 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][0])]} del var['config'][0]['type'] r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], var['config'][0]['ports']) self.assertEquals(r[0]['status'], 'Fail')
def test_fail_multi_network(self, cmd): """ Verify the results when there are multiple networks and one fails :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True, True, 'eth1'] + [False] + [True] * 3 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][1])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], 'eth1.100') self.assertEquals(r[0]['status'], 'Fail') self.assertEquals(r[1]['status'], 'Pass')
def test_team_incorrect_team_port_cfg(self, cmd): """ Failure when there is an incorrect port configuration option :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 3 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][4])]} var['config'][0]['team_port_cfg'].pop() r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], var['config'][0]['ports']) self.assertEquals(r[0]['status'], 'Fail')
def test_team_missing_team_port_cfg(self, cmd): """ Failure when a required attribute is missing :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 3 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][4])]} del var['config'][0]['team_port_cfg'] r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], var['config'][0]['ports']) self.assertEquals(r[0]['status'], 'Fail')
def test_invalid_network_info(self, cmd, net): """ Verify the results when there are multiple networks and one fails :param cmd: Handle to mock method _remote_cmd :param net: Handle to mock method _verify_network_info :return: """ cmd.side_effect = [True, True, 'eth1', True] var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][0])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], 'eth1') self.assertEquals(r[0]['status'], 'Fail')
def test_team_cfg_net_pass(self, cmd): """ Failure to configure team network :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 10 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][4])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], 'team1.200') self.assertEquals(r[0]['status'], 'Pass') self.assertEquals(r[1]['ports'], 'team1.201') self.assertEquals(r[1]['status'], 'Pass')
def test_bond_multi_network_fail(self, cmd): """ Verify the result when there is a failure in one of the networks :param cmd: Handle to mock method _remote_cmd :return: """ cmd.side_effect = [True] * 3 + [False] + [True] * 6 var = {"host": redhat_host, "config": [deepcopy(rhel_conf['config'][3])]} r = RedHatNetConfig().configure_network(var) self.assertEquals(r[0]['ports'], 'bond1.200') self.assertEquals(r[0]['status'], 'Fail') self.assertEquals(r[1]['ports'], 'bond1.201') self.assertEquals(r[1]['status'], 'Pass')