예제 #1
0
파일: test_vif.py 프로젝트: hsluoyz/patron
 def test_ensure_vlan_bridge_with_network(self):
     self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
     self.mox.StubOutWithMock(network_util,
         'get_vswitch_for_vlan_interface')
     self.mox.StubOutWithMock(network_util,
         'check_if_vlan_interface_exists')
     self.mox.StubOutWithMock(network_util, 'create_port_group')
     vm_network = {'name': 'VM Network', 'type': 'Network'}
     network_util.get_network_with_the_name(self.session, 'fa0',
         self.cluster).AndReturn(vm_network)
     self.mox.ReplayAll()
     vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
예제 #2
0
 def test_ensure_vlan_bridge_with_network(self):
     self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
     self.mox.StubOutWithMock(network_util,
                              'get_vswitch_for_vlan_interface')
     self.mox.StubOutWithMock(network_util,
                              'check_if_vlan_interface_exists')
     self.mox.StubOutWithMock(network_util, 'create_port_group')
     vm_network = {'name': 'VM Network', 'type': 'Network'}
     network_util.get_network_with_the_name(
         self.session, 'fa0', self.cluster).AndReturn(vm_network)
     self.mox.ReplayAll()
     vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
예제 #3
0
    def test_get_network_no_match(self):
        net_morefs = [
            vim_util.get_moref("dvportgroup-135",
                               "DistributedVirtualPortgroup"),
            vim_util.get_moref("dvportgroup-136",
                               "DistributedVirtualPortgroup")
        ]
        networks = self._build_cluster_networks(net_morefs)
        self._continue_retrieval_called = False

        def mock_call_method(module, method, *args, **kwargs):
            if method == 'get_object_properties':
                return networks
            if method == 'get_dynamic_property':
                result = fake.DataObject()
                result.name = 'no-match'
                return result
            if method == 'continue_retrieval':
                self._continue_retrieval_called = True

        with mock.patch.object(self._session, '_call_method',
                               mock_call_method):
            res = network_util.get_network_with_the_name(
                self._session, 'fake_net', 'fake_cluster')
            self.assertTrue(self._continue_retrieval_called)
            self.assertIsNone(res)
예제 #4
0
    def _get_network_dvs_match(self, name, token=False):
        net_morefs = [
            vim_util.get_moref("dvportgroup-135",
                               "DistributedVirtualPortgroup")
        ]
        networks = self._build_cluster_networks(net_morefs)

        def mock_call_method(module, method, *args, **kwargs):
            if method == 'get_object_properties':
                return networks
            if method == 'get_dynamic_property':
                result = fake.DataObject()
                if not token or self._continue_retrieval_called:
                    result.name = name
                else:
                    result.name = 'fake_name'
                result.key = 'fake_key'
                result.distributedVirtualSwitch = 'fake_dvs'
                return result
            if method == 'continue_retrieval':
                if token:
                    self._continue_retrieval_called = True
                    return networks
            if method == 'cancel_retrieval':
                self._cancel_retrieval_called = True

        with mock.patch.object(self._session, '_call_method',
                               mock_call_method):
            res = network_util.get_network_with_the_name(
                self._session, 'fake_net', 'fake_cluster')
            self.assertIsNotNone(res)
예제 #5
0
 def test_get_neutron_network_bridge_network_not_found(self):
     self.mox.StubOutWithMock(vm_util, 'get_host_ref')
     self.mox.StubOutWithMock(self.session, '_call_method')
     self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
     vm_util.get_host_ref(self.session, self.cluster).AndReturn('fake-host')
     opaque = fake.DataObject()
     opaque.HostOpaqueNetworkInfo = ['fake-network-info']
     self.session._call_method(
         vim_util, "get_dynamic_property", 'fake-host', 'HostSystem',
         'config.network.opaqueNetwork').AndReturn(None)
     network_util.get_network_with_the_name(self.session, 0,
                                            self.cluster).AndReturn(None)
     self.mox.ReplayAll()
     self.assertRaises(exception.NetworkNotFoundForBridge,
                       vif.get_neutron_network, self.session,
                       self.vif['network']['id'], self.cluster, self.vif)
예제 #6
0
파일: test_vif.py 프로젝트: hsluoyz/patron
 def test_get_neutron_network_bridge_network_not_found(self):
     self.mox.StubOutWithMock(vm_util, 'get_host_ref')
     self.mox.StubOutWithMock(self.session, '_call_method')
     self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
     vm_util.get_host_ref(self.session,
             self.cluster).AndReturn('fake-host')
     opaque = fake.DataObject()
     opaque.HostOpaqueNetworkInfo = ['fake-network-info']
     self.session._call_method(vim_util, "get_dynamic_property",
              'fake-host', 'HostSystem',
              'config.network.opaqueNetwork').AndReturn(None)
     network_util.get_network_with_the_name(self.session, 0,
         self.cluster).AndReturn(None)
     self.mox.ReplayAll()
     self.assertRaises(exception.NetworkNotFoundForBridge,
                       vif.get_neutron_network, self.session,
                       self.vif['network']['id'], self.cluster, self.vif)
예제 #7
0
파일: test_vif.py 프로젝트: hsluoyz/patron
    def test_ensure_vlan_bridge_with_existing_dvs(self):
        network_ref = {'dvpg': 'dvportgroup-2062',
                       'type': 'DistributedVirtualPortgroup'}
        self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
        self.mox.StubOutWithMock(network_util,
            'get_vswitch_for_vlan_interface')
        self.mox.StubOutWithMock(network_util,
            'check_if_vlan_interface_exists')
        self.mox.StubOutWithMock(network_util, 'create_port_group')

        network_util.get_network_with_the_name(self.session, 'fa0',
            self.cluster).AndReturn(network_ref)
        self.mox.ReplayAll()
        ref = vif.ensure_vlan_bridge(self.session,
                                     self.vif,
                                     create_vlan=False)
        self.assertThat(ref, matchers.DictMatches(network_ref))
예제 #8
0
    def test_ensure_vlan_bridge_with_existing_dvs(self):
        network_ref = {
            'dvpg': 'dvportgroup-2062',
            'type': 'DistributedVirtualPortgroup'
        }
        self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
        self.mox.StubOutWithMock(network_util,
                                 'get_vswitch_for_vlan_interface')
        self.mox.StubOutWithMock(network_util,
                                 'check_if_vlan_interface_exists')
        self.mox.StubOutWithMock(network_util, 'create_port_group')

        network_util.get_network_with_the_name(
            self.session, 'fa0', self.cluster).AndReturn(network_ref)
        self.mox.ReplayAll()
        ref = vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
        self.assertThat(ref, matchers.DictMatches(network_ref))
예제 #9
0
파일: vif.py 프로젝트: hsluoyz/patron
def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
    """Create a vlan and bridge unless they already exist."""
    vlan_num = vif['network'].get_meta('vlan')
    bridge = vif['network']['bridge']
    vlan_interface = CONF.vmware.vlan_interface

    network_ref = network_util.get_network_with_the_name(session, bridge,
                                                         cluster)
    if network_ref and network_ref['type'] == 'DistributedVirtualPortgroup':
        return network_ref

    if not network_ref:
        # Create a port group on the vSwitch associated with the
        # vlan_interface corresponding physical network adapter on the ESX
        # host.
        vswitch_associated = _get_associated_vswitch_for_interface(session,
                                 vlan_interface, cluster)
        network_util.create_port_group(session, bridge,
                                       vswitch_associated,
                                       vlan_num if create_vlan else 0,
                                       cluster)
        network_ref = network_util.get_network_with_the_name(session,
                                                             bridge,
                                                             cluster)
    elif create_vlan:
        # Get the vSwitch associated with the Physical Adapter
        vswitch_associated = _get_associated_vswitch_for_interface(session,
                                 vlan_interface, cluster)
        # Get the vlan id and vswitch corresponding to the port group
        _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
        pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)

        # Check if the vswitch associated is proper
        if pg_vswitch != vswitch_associated:
            raise exception.InvalidVLANPortGroup(
                bridge=bridge, expected=vswitch_associated,
                actual=pg_vswitch)

        # Check if the vlan id is proper for the port group
        if pg_vlanid != vlan_num:
            raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
                                       pgroup=pg_vlanid)
    return network_ref
예제 #10
0
파일: test_vif.py 프로젝트: hsluoyz/patron
    def test_ensure_vlan_bridge_without_vlan(self):
        self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
        self.mox.StubOutWithMock(network_util,
            'get_vswitch_for_vlan_interface')
        self.mox.StubOutWithMock(network_util,
            'check_if_vlan_interface_exists')
        self.mox.StubOutWithMock(network_util, 'create_port_group')

        network_util.get_network_with_the_name(self.session, 'fa0',
            self.cluster).AndReturn(None)
        network_util.get_vswitch_for_vlan_interface(self.session, 'vmnet0',
            self.cluster).AndReturn('vmnet0')
        network_util.check_if_vlan_interface_exists(self.session, 'vmnet0',
        self.cluster).AndReturn(True)
        network_util.create_port_group(self.session, 'fa0', 'vmnet0', 0,
            self.cluster)
        network_util.get_network_with_the_name(self.session, 'fa0', None)
        self.mox.ReplayAll()
        vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
예제 #11
0
    def test_ensure_vlan_bridge_without_vlan(self):
        self.mox.StubOutWithMock(network_util, 'get_network_with_the_name')
        self.mox.StubOutWithMock(network_util,
                                 'get_vswitch_for_vlan_interface')
        self.mox.StubOutWithMock(network_util,
                                 'check_if_vlan_interface_exists')
        self.mox.StubOutWithMock(network_util, 'create_port_group')

        network_util.get_network_with_the_name(self.session, 'fa0',
                                               self.cluster).AndReturn(None)
        network_util.get_vswitch_for_vlan_interface(
            self.session, 'vmnet0', self.cluster).AndReturn('vmnet0')
        network_util.check_if_vlan_interface_exists(
            self.session, 'vmnet0', self.cluster).AndReturn(True)
        network_util.create_port_group(self.session, 'fa0', 'vmnet0', 0,
                                       self.cluster)
        network_util.get_network_with_the_name(self.session, 'fa0', None)
        self.mox.ReplayAll()
        vif.ensure_vlan_bridge(self.session, self.vif, create_vlan=False)
예제 #12
0
파일: vif.py 프로젝트: 2Exception/patron
def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
    """Create a vlan and bridge unless they already exist."""
    vlan_num = vif['network'].get_meta('vlan')
    bridge = vif['network']['bridge']
    vlan_interface = CONF.vmware.vlan_interface

    network_ref = network_util.get_network_with_the_name(
        session, bridge, cluster)
    if network_ref and network_ref['type'] == 'DistributedVirtualPortgroup':
        return network_ref

    if not network_ref:
        # Create a port group on the vSwitch associated with the
        # vlan_interface corresponding physical network adapter on the ESX
        # host.
        vswitch_associated = _get_associated_vswitch_for_interface(
            session, vlan_interface, cluster)
        network_util.create_port_group(session, bridge, vswitch_associated,
                                       vlan_num if create_vlan else 0, cluster)
        network_ref = network_util.get_network_with_the_name(
            session, bridge, cluster)
    elif create_vlan:
        # Get the vSwitch associated with the Physical Adapter
        vswitch_associated = _get_associated_vswitch_for_interface(
            session, vlan_interface, cluster)
        # Get the vlan id and vswitch corresponding to the port group
        _get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
        pg_vlanid, pg_vswitch = _get_pg_info(session, bridge, cluster)

        # Check if the vswitch associated is proper
        if pg_vswitch != vswitch_associated:
            raise exception.InvalidVLANPortGroup(bridge=bridge,
                                                 expected=vswitch_associated,
                                                 actual=pg_vswitch)

        # Check if the vlan id is proper for the port group
        if pg_vlanid != vlan_num:
            raise exception.InvalidVLANTag(bridge=bridge,
                                           tag=vlan_num,
                                           pgroup=pg_vlanid)
    return network_ref
예제 #13
0
    def test_get_network_network_match(self):
        net_morefs = [vim_util.get_moref("network-54", "Network")]
        networks = self._build_cluster_networks(net_morefs)

        def mock_call_method(module, method, *args, **kwargs):
            if method == 'get_object_properties':
                return networks
            if method == 'get_dynamic_property':
                return 'fake_net'

        with mock.patch.object(self._session, '_call_method',
                               mock_call_method):
            res = network_util.get_network_with_the_name(
                self._session, 'fake_net', 'fake_cluster')
            self.assertIsNotNone(res)
예제 #14
0
파일: vif.py 프로젝트: 2Exception/patron
def get_neutron_network(session, network_name, cluster, vif):
    opaque = None
    if vif['type'] != model.VIF_TYPE_DVS:
        opaque = _get_opaque_network(session, cluster)
    if opaque:
        bridge = vif['network']['id']
        opaque_networks = opaque.HostOpaqueNetworkInfo
        network_ref = _get_network_ref_from_opaque(
            opaque_networks, CONF.vmware.integration_bridge, bridge)
    else:
        bridge = network_name
        network_ref = network_util.get_network_with_the_name(
            session, network_name, cluster)
    if not network_ref:
        raise exception.NetworkNotFoundForBridge(bridge=bridge)
    return network_ref
예제 #15
0
파일: vif.py 프로젝트: hsluoyz/patron
def get_neutron_network(session, network_name, cluster, vif):
    opaque = None
    if vif['type'] != model.VIF_TYPE_DVS:
        opaque = _get_opaque_network(session, cluster)
    if opaque:
        bridge = vif['network']['id']
        opaque_networks = opaque.HostOpaqueNetworkInfo
        network_ref = _get_network_ref_from_opaque(opaque_networks,
                CONF.vmware.integration_bridge, bridge)
    else:
        bridge = network_name
        network_ref = network_util.get_network_with_the_name(
                session, network_name, cluster)
    if not network_ref:
        raise exception.NetworkNotFoundForBridge(bridge=bridge)
    return network_ref