def test_apply_net_target_and_config(self):
        self.m_load_config.return_value = self.network_config
        self.m_netpass_avail.return_value = False
        self.m_net_parsedata.return_value = self.ns

        apply_net.apply_net(self.target, network_state=None,
                            network_config=self.network_config)

        self.m_netpass_avail.assert_called_with(self.target)

        self.m_net_renderstate.assert_called_with(target=self.target,
                                                  network_state=self.ns)
        self.m_legacy.assert_called_with(self.target)
        self.m_ipv6_priv.assert_called_with(self.target)
        self.m_ipv6_mtu.assert_called_with(self.target)
Esempio n. 2
0
def apply_networking(target, state):
    netconf = state.get('network_config')
    interfaces = state.get('interfaces')

    def is_valid_src(infile):
        with open(infile, 'r') as fp:
            content = fp.read()
            if len(content.split('\n')) > 1:
                return True
        return False

    if is_valid_src(netconf):
        LOG.info("applying network_config")
        apply_net.apply_net(target, network_state=None, network_config=netconf)
    else:
        LOG.debug("copying interfaces")
        copy_interfaces(interfaces, target)
    def test_apply_net_target_and_config_passthrough(self):
        self.m_load_config.return_value = self.network_config
        self.m_netpass_avail.return_value = True

        netcfg = "network_config.yaml"
        apply_net.apply_net(self.target, network_state=None,
                            network_config=netcfg)

        self.assertFalse(self.m_ns_from_file.called)
        self.m_load_config.assert_called_with(netcfg)
        self.m_netpass_avail.assert_called_with(self.target)
        nc = self.network_config
        self.m_netpass_render.assert_called_with(self.target, netconfig=nc)

        self.assertFalse(self.m_net_renderstate.called)
        self.m_legacy.assert_called_with(self.target)
        self.m_ipv6_priv.assert_called_with(self.target)
        self.m_ipv6_mtu.assert_called_with(self.target)
    def test_apply_net_target_and_config_passthrough_v2_not_available(self):
        nc = copy.deepcopy(self.network_config)
        nc['network']['version'] = 2
        self.m_load_config.return_value = nc
        self.m_netpass_avail.return_value = False
        self.m_net_parsedata.return_value = self.ns

        netcfg = "network_config.yaml"

        apply_net.apply_net(self.target, network_state=None,
                            network_config=netcfg)

        self.assertFalse(self.m_ns_from_file.called)
        self.m_load_config.assert_called_with(netcfg)
        self.m_netpass_avail.assert_called_with(self.target)
        self.assertFalse(self.m_netpass_render.called)
        self.m_net_parsedata.assert_called_with(nc['network'])

        self.m_net_renderstate.assert_called_with(
            target=self.target, network_state=self.ns)
        self.m_legacy.assert_called_with(self.target)
        self.m_ipv6_priv.assert_called_with(self.target)
        self.m_ipv6_mtu.assert_called_with(self.target)