Esempio n. 1
0
def _setup_nmstate(networks, bondings, options, in_rollback):
    """
    Setup the networks using nmstate as the backend provider.
    nmstate handles the rollback by itself in case of an error during the
    transaction or in case the resulted state does not include the desired one.

    In order to support the connectivity check, the "regular" rollback is
    used (the Transaction context).
    """
    logging.info('Processing setup through nmstate')
    desired_state = nmstate.generate_state(networks, bondings)
    logging.info('Desired state: %s', desired_state)
    nmstate.setup(desired_state, verify_change=not in_rollback)
    with Transaction(in_rollback=in_rollback) as config:
        config.networks = {
            name: attrs
            for name, attrs in six.viewitems(networks)
            if not attrs.get('remove')
        }
        config.bonds = {
            name: attrs
            for name, attrs in six.viewitems(bondings)
            if not attrs.get('remove')
        }
        connectivity.check(options)
Esempio n. 2
0
def _setup_nmstate(networks, bondings, options, in_rollback):
    """
    Setup the networks using nmstate as the backend provider.
    nmstate handles the rollback by itself in case of an error during the
    transaction or in case the resulted state does not include the desired one.

    In order to support the connectivity check, the "regular" rollback is
    used (the Transaction context).
    """
    logging.info('Processing setup through nmstate')
    desired_state = nmstate.generate_state(networks, bondings)
    logging.info('Desired state: %s', desired_state)
    _setup_dynamic_src_routing(networks)
    nmstate.setup(desired_state, verify_change=not in_rollback)
    net_info = NetInfo(netinfo_get())

    with Transaction(in_rollback=in_rollback, persistent=False) as config:
        _setup_qos(networks, net_info, config.networks)
        for net_name, net_attrs in six.viewitems(networks):
            if net_attrs.get('remove'):
                config.removeNetwork(net_name)
        for net_name, net_attrs in six.viewitems(networks):
            if not net_attrs.get('remove'):
                config.setNetwork(net_name, net_attrs)
        for bond_name, bond_attrs in six.viewitems(bondings):
            if bond_attrs.get('remove'):
                config.removeBonding(bond_name)
        for bond_name, bond_attrs in six.viewitems(bondings):
            if not bond_attrs.get('remove'):
                config.setBonding(bond_name, bond_attrs)
        _setup_static_src_routing(networks)
        config.save()
        link_setup.setup_custom_bridge_opts(networks)
        connectivity.check(options)
Esempio n. 3
0
    def test_failed_setup_in_rollback(self):
        with self.assertRaises(TestException):
            with Transaction(config=self.config, in_rollback=True) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                raise TestException()

        file_path = os.path.join(self.tempdir, 'nets', NETWORK)
        self.assertFalse(os.path.exists(file_path))
Esempio n. 4
0
    def test_successful_non_persistent_setup(self):
        with Transaction(config=self.config, persistent=False) as _config:
            _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
            _config.setBonding(BONDING, BONDING_ATTRIBUTES)
            _config.set_device(DEVICE, DEVICE_ATTRIBUTES)

        self.assertFalse(os.path.exists(self.net_path))
        self.assertFalse(os.path.exists(self.bond_path))
        self.assertFalse(os.path.exists(self.device_path))
Esempio n. 5
0
    def test_successful_non_persistent_setup(self, config, groups_paths):
        with Transaction(config=config, persistent=False) as _config:
            _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
            _config.setBonding(BONDING, BONDING_ATTRIBUTES)
            _config.set_device(DEVICE, DEVICE_ATTRIBUTES)

        net_path, bond_path, dev_path = groups_paths
        assert not os.path.exists(net_path)
        assert not os.path.exists(bond_path)
        assert not os.path.exists(dev_path)
Esempio n. 6
0
    def test_failed_setup(self):
        with self.assertRaises(ne.RollbackIncomplete) as roi:
            with Transaction(config=self.config) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                raise TestException()

        diff, ex_type, _ = roi.exception
        self.assertEquals(diff.networks[NETWORK], {'remove': True})
        self.assertEquals(ex_type, TestException)
        file_path = os.path.join(self.tempdir, 'nets', NETWORK)
        self.assertFalse(os.path.exists(file_path))
Esempio n. 7
0
    def test_failed_setup_in_rollback(self):
        with self.assertRaises(TestException):
            with Transaction(config=self.config, in_rollback=True) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                _config.setBonding(BONDING, BONDING_ATTRIBUTES)
                _config.set_device(DEVICE, DEVICE_ATTRIBUTES)
                raise TestException()

        self.assertFalse(os.path.exists(self.net_path))
        self.assertFalse(os.path.exists(self.bond_path))
        self.assertFalse(os.path.exists(self.device_path))
Esempio n. 8
0
    def test_failed_setup_in_rollback(self, config, groups_paths):
        with pytest.raises(FailTest):
            with Transaction(config=config, in_rollback=True) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                _config.setBonding(BONDING, BONDING_ATTRIBUTES)
                _config.set_device(DEVICE, DEVICE_ATTRIBUTES)
                raise FailTest()

        net_path, bond_path, dev_path = groups_paths
        assert not os.path.exists(net_path)
        assert not os.path.exists(bond_path)
        assert not os.path.exists(dev_path)
Esempio n. 9
0
    def test_failed_setup(self):
        with self.assertRaises(ne.RollbackIncomplete) as roi:
            with Transaction(config=self.config) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                _config.setBonding(BONDING, BONDING_ATTRIBUTES)
                _config.set_device(DEVICE, DEVICE_ATTRIBUTES)
                raise TestException()

        diff = roi.exception.diff
        self.assertEqual(diff.networks[NETWORK], {'remove': True})
        self.assertEqual(diff.bonds[BONDING], {'remove': True})
        self.assertEqual(diff.devices, {})
        self.assertEqual(roi.exception.exc_type, TestException)
        self.assertFalse(os.path.exists(self.net_path))
        self.assertFalse(os.path.exists(self.bond_path))
        self.assertFalse(os.path.exists(self.device_path))
Esempio n. 10
0
def _setup_ovs(networks, bondings, options, net_info, in_rollback):
    _ovs_info = ovs_info.OvsInfo()
    ovs_nets = ovs_info.create_netinfo(_ovs_info)['networks']

    nets2add, nets2edit, nets2remove = _split_setup_actions(networks, ovs_nets)
    bonds2add, bonds2edit, bonds2remove = _split_setup_actions(
        bondings, net_info['bondings'])

    # TODO: If a nework is to be edited, we remove it and recreate again.
    # We should implement editation.
    nets2add.update(nets2edit)
    nets2remove.update(nets2edit)

    # FIXME: we are not able to move a nic from bond to network in one setup
    with Transaction(in_rollback=in_rollback) as config:
        setup_bonds = SetupBonds(bonds2add, bonds2edit, bonds2remove, config)
        with ifacquire.Transaction(ovs_nets) as acq:
            _remove_networks(nets2remove, _ovs_info, config)

            setup_bonds.remove_bonds()

            # Post removal of nets, update ovs_nets.
            ovs_nets = ovs_info.create_netinfo(_ovs_info)['networks']
            kernel_bonds = bond.Bond.bonds()
            validator.validate_nic_usage(
                nets2add,
                bonds2add,
                _get_kernel_nets_nics(ovs_nets, kernel_bonds),
                _get_kernel_bonds_slaves(kernel_bonds),
            )

            acq.acquire(setup_bonds.ifaces_for_acquirement)
            setup_bonds.edit_bonds()
            setup_bonds.add_bonds()

            _add_networks(nets2add, _ovs_info, config, acq)

            ovs_switch.update_network_to_bridge_mappings(ovs_info.OvsInfo())

            setup_ipv6autoconf(networks)
            set_ovs_links_up(nets2add, bonds2add, bonds2edit)
            setup_ovs_ip_config(nets2add, nets2remove)

            _setup_ovs_dns(nets2add)

            connectivity.check(options)
Esempio n. 11
0
    def test_failed_setup(self, config, groups_paths):
        with pytest.raises(ne.RollbackIncomplete) as roi:
            with Transaction(config=config) as _config:
                _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)
                _config.setBonding(BONDING, BONDING_ATTRIBUTES)
                _config.set_device(DEVICE, DEVICE_ATTRIBUTES)
                raise FailTest()

        diff = roi.value.diff
        assert diff.networks[NETWORK] == {'remove': True}
        assert diff.bonds[BONDING] == {'remove': True}
        assert diff.devices == {}
        assert roi.value.exc_type == FailTest
        net_path, bond_path, dev_path = groups_paths
        assert not os.path.exists(net_path)
        assert not os.path.exists(bond_path)
        assert not os.path.exists(dev_path)
Esempio n. 12
0
def _setup_nmstate(networks, bondings, options, in_rollback, net_info):
    """
    Setup the networks using nmstate as the backend provider.
    nmstate handles the rollback by itself in case of an error during the
    transaction or in case the resulted state does not include the desired one.

    In order to support the connectivity check, the "regular" rollback is
    used (the Transaction context).
    """
    logging.info('Processing setup through nmstate')
    desired_state = nmstate.generate_state(networks, bondings)
    logging.info('Desired state: %s', desired_state)
    _setup_dynamic_src_routing(networks)

    vlan_ifaces_states = _generate_vlan_ifaces_states(desired_state, net_info)
    logging.info('Reapply VLANs desired state: %s', vlan_ifaces_states)

    nmstate.setup(desired_state, verify_change=not in_rollback)
    if vlan_ifaces_states:
        nmstate.setup({'interfaces': vlan_ifaces_states},
                      verify_change=not in_rollback)
    with Transaction(in_rollback=in_rollback) as config:
        for net_name, net_attrs in six.viewitems(networks):
            if net_attrs.get('remove'):
                config.removeNetwork(net_name)
        for net_name, net_attrs in six.viewitems(networks):
            if not net_attrs.get('remove'):
                config.setNetwork(net_name, net_attrs)
        for bond_name, bond_attrs in six.viewitems(bondings):
            if bond_attrs.get('remove'):
                config.removeBonding(bond_name)
        for bond_name, bond_attrs in six.viewitems(bondings):
            if not bond_attrs.get('remove'):
                config.setBonding(bond_name, bond_attrs)
        _setup_static_src_routing(networks)
        connectivity.check(options)
Esempio n. 13
0
 def test_failed_setup_with_no_diff(self):
     with self.assertRaises(TestException):
         with Transaction(config=self.config):
             raise TestException()
Esempio n. 14
0
    def test_successful_non_persistent_setup(self):
        with Transaction(config=self.config, persistent=False) as _config:
            _config.setNetwork(NETWORK, NETWORK_ATTRIBUTES)

        file_path = os.path.join(self.tempdir, 'nets', NETWORK)
        self.assertFalse(os.path.exists(file_path))
Esempio n. 15
0
 def test_failed_setup_with_no_diff(self, config):
     with pytest.raises(FailTest):
         with Transaction(config=config):
             raise FailTest()