Beispiel #1
0
    def test_given_ovs_hostconfigs(self):
        # given
        self.patch_os_geteuid()
        ovs_hostconfigs = {
            "ODL L2": {
                "allowed_network_types": ["a", "b", "c"]
            }
        }
        args = [
            '--ovs_hostconfigs=' + jsonutils.dumps(ovs_hostconfigs),
            '--bridge_mappings=a:1,b:2'
        ]
        execute = self.patch_utils_execute()
        conf = set_ovs_hostconfigs.setup_conf(args)

        # when
        result = set_ovs_hostconfigs.main(args)

        # then
        self.assertEqual(0, result)
        execute.assert_has_calls([
            mock.call(('ovs-vsctl', 'get', 'Open_vSwitch', '.', '_uuid')),
            mock.call(('ovs-vsctl', 'set', 'Open_vSwitch', '<some-uuid>',
                       'external_ids:odl_os_hostconfig_hostid=' + conf.host)),
            mock.call(('ovs-vsctl', 'set', 'Open_vSwitch', '<some-uuid>',
                       match.wildcard(
                           'external_ids:odl_os_hostconfig_config_odl_l2=*'))),
        ])

        expected = ovs_hostconfigs['ODL L2']
        _, actual_json = execute.call_args_list[2][0][0][4].split("=", 1)
        self.assertEqual(match.json(expected), actual_json)
    def test_given_ovs_hostconfigs(self):
        # given
        self.patch_os_geteuid()
        ovs_hostconfigs = {
            "ODL L2": {"allowed_network_types": ["a", "b", "c"]}}
        args = ['--ovs_hostconfigs=' + jsonutils.dumps(ovs_hostconfigs),
                '--bridge_mappings=a:1,b:2']
        execute = self.patch_utils_execute()
        conf = set_ovs_hostconfigs.setup_conf(args)

        # when
        result = set_ovs_hostconfigs.main(args)

        # then
        self.assertEqual(0, result)
        execute.assert_has_calls([
            mock.call(
                ('ovs-vsctl', 'get', 'Open_vSwitch', '.', '_uuid')),
            mock.call(
                ('ovs-vsctl', 'set', 'Open_vSwitch', '<some-uuid>',
                 'external_ids:odl_os_hostconfig_hostid=' + conf.host)),
            mock.call(
                ('ovs-vsctl', 'set', 'Open_vSwitch', '<some-uuid>',
                 match.wildcard(
                     'external_ids:odl_os_hostconfig_config_odl_l2=*'))),
        ])

        expected = ovs_hostconfigs['ODL L2']
        _, actual_json = execute.call_args_list[2][0][0][4].split("=", 1)
        self.assertEqual(match.json(expected), actual_json)
Beispiel #3
0
    def _test_given_args(self, *args):
        # given
        self.patch_os_geteuid()
        execute = self.patch_utils_execute()
        conf = set_ovs_hostconfigs.setup_conf(*args)

        datapath_type = conf.datapath_type
        if datapath_type is None:
            if conf.ovs_dpdk is False:
                datapath_type = "system"
            else:
                datapath_type = "netdev"

        # when
        result = set_ovs_hostconfigs.main(*args)

        # then
        self.assertEqual(0, result)
        execute.assert_has_calls([
            mock.call(('ovs-vsctl', 'get', 'Open_vSwitch', '.', '_uuid')),
            mock.call(
                ('ovs-vsctl', 'get', 'Open_vSwitch', '.', 'datapath_types')),
            mock.call(('ovs-vsctl', 'set', 'Open_vSwitch', '<some-uuid>',
                       'external_ids:odl_os_hostconfig_hostid=' + conf.host)),
            mock.call(('ovs-vsctl', 'set', 'Open_vSwitch', '<some-uuid>',
                       match.wildcard(
                           'external_ids:odl_os_hostconfig_config_odl_l2=*'))),
        ])

        host_addresses = [conf.host or conf.local_ip]
        if datapath_type == "system":
            vif_type = "ovs"
            vif_details = {
                "uuid": '<some-uuid>',
                "host_addresses": host_addresses,
                "has_datapath_type_netdev": False,
                "support_vhost_user": False
            }
        else:  # datapath_type in ["system", "netdev"]
            vif_type = "vhostuser"
            vif_details = {
                "uuid":
                '<some-uuid>',
                "host_addresses":
                host_addresses,
                "has_datapath_type_netdev":
                True,
                "support_vhost_user":
                True,
                "port_prefix":
                conf.vhostuser_port_prefix,
                "vhostuser_mode":
                conf.vhostuser_mode,
                "vhostuser_ovs_plug":
                conf.vhostuser_ovs_plug,
                "vhostuser_socket_dir":
                conf.vhostuser_socket_dir,
                "vhostuser_socket":
                os.path.join(conf.vhostuser_socket_dir,
                             conf.vhostuser_port_prefix + "$PORT_ID"),
            }

        _, actual_json = execute.call_args_list[3][0][0][4].split("=", 1)
        expected = {
            "allowed_network_types":
            conf.allowed_network_types,
            "bridge_mappings":
            conf.bridge_mappings,
            "datapath_type":
            datapath_type,
            "supported_vnic_types": [{
                "vif_type": vif_type,
                "vnic_type": "normal",
                "vif_details": vif_details
            }]
        }

        if vif_type == 'ovs' and conf.ovs_sriov_offload:
            direct_vnic = {
                "vif_details": vif_details,
                "vif_type": vif_type,
                "vnic_type": "direct",
            }
            expected["supported_vnic_types"].append(direct_vnic)
        self.assertEqual(match.json(expected), actual_json)
    def _test_given_args(self, *args):
        # given
        self.patch_os_geteuid()
        execute = self.patch_utils_execute()
        conf = set_ovs_hostconfigs.setup_conf(*args)

        datapath_type = conf.datapath_type
        if datapath_type is None:
            if conf.ovs_dpdk is False:
                datapath_type = "system"
            else:
                datapath_type = "netdev"

        # when
        result = set_ovs_hostconfigs.main(*args)

        # then
        self.assertEqual(0, result)
        execute.assert_has_calls([
            mock.call(
                ('ovs-vsctl', 'get', 'Open_vSwitch', '.', '_uuid')),
            mock.call(
                ('ovs-vsctl', 'get', 'Open_vSwitch', '.', 'datapath_types')),
            mock.call(
                ('ovs-vsctl', 'set', 'Open_vSwitch', '<some-uuid>',
                 'external_ids:odl_os_hostconfig_hostid=' + conf.host)),
            mock.call(
                ('ovs-vsctl', 'set', 'Open_vSwitch', '<some-uuid>',
                 match.wildcard(
                     'external_ids:odl_os_hostconfig_config_odl_l2=*'))),
        ])

        host_addresses = [conf.host or conf.local_ip]
        if datapath_type == "system":
            vif_type = "ovs"
            vif_details = {
                "uuid": '<some-uuid>',
                "host_addresses": host_addresses,
                "has_datapath_type_netdev": False,
                "support_vhost_user": False
            }
        else:  # datapath_type in ["system", "netdev"]
            vif_type = "vhostuser"
            vif_details = {
                "uuid": '<some-uuid>',
                "host_addresses": host_addresses,
                "has_datapath_type_netdev": True,
                "support_vhost_user": True,
                "port_prefix": conf.vhostuser_port_prefix,
                "vhostuser_mode": conf.vhostuser_mode,
                "vhostuser_ovs_plug": conf.vhostuser_ovs_plug,
                "vhostuser_socket_dir": conf.vhostuser_socket_dir,
                "vhostuser_socket": os.path.join(
                    conf.vhostuser_socket_dir,
                    conf.vhostuser_port_prefix + "$PORT_ID"),
            }

        _, actual_json = execute.call_args_list[3][0][0][4].split("=", 1)
        expected = {
            "allowed_network_types": conf.allowed_network_types,
            "bridge_mappings": conf.bridge_mappings,
            "datapath_type": datapath_type,
            "supported_vnic_types": [
                {
                    "vif_type": vif_type,
                    "vnic_type": "normal",
                    "vif_details": vif_details
                }
            ]
        }

        if vif_type == 'ovs' and conf.ovs_sriov_offload:
            direct_vnic = {
                "vif_details": vif_details,
                "vif_type": vif_type,
                "vnic_type": "direct",
            }
            expected["supported_vnic_types"].append(direct_vnic)
        self.assertEqual(match.json(expected), actual_json)