Exemplo n.º 1
0
 def test_plug_vifs_bridge_two_interfaces(self):
     calls = [
         # interface 1
         mock.call('ip', 'link', 'add', 'name', 'tap920be2f4-2b',
                   'type', 'veth', 'peer', 'name', 'ns920be2f4-2b',
                   run_as_root=True),
         mock.call('ip', 'link', 'set', 'tap920be2f4-2b', 'address',
                   'fe:16:3e:ff:ff:ff', run_as_root=True),
         mock.call('brctl', 'addif', 'br100', 'tap920be2f4-2b',
                   run_as_root=True),
         mock.call('ip', 'link', 'set', 'tap920be2f4-2b', 'up',
                   run_as_root=True),
         # interface 2
         mock.call('ip', 'link', 'add', 'name', 'tap920be2f4-2b',
                   'type', 'veth', 'peer', 'name', 'ns920be2f4-2b',
                   run_as_root=True),
         mock.call('ip', 'link', 'set', 'tap920be2f4-2b', 'address',
                   'fe:16:3e:ff:ff:ff', run_as_root=True),
         mock.call('brctl', 'addif', 'br100', 'tap920be2f4-2b',
                   run_as_root=True),
         mock.call('ip', 'link', 'set', 'tap920be2f4-2b', 'up',
                   run_as_root=True),
     ]
     network_info = [self.vif_bridge, self.vif_bridge]
     with mock.patch('nova.utils.execute') as ex:
         driver = docker_driver.DockerDriver(object)
         driver.plug_vifs({'name': 'fake_instance'}, network_info)
         ex.assert_has_calls(calls)
 def test_unplug_vifs_ovs(self, mock_ui):
     iface_id = '920be2f4-2b98-411e-890a-69bcabb2a5a0'
     fake_net_info = [{
         'network': {
             'bridge':
             'br-int',
             'subnets': [{
                 'gateway': {
                     'address': '10.11.12.1'
                 },
                 'cidr':
                 '10.11.12.0/24',
                 'ips': [{
                     'address': '10.11.12.3',
                     'type': 'fixed',
                     'version': 4
                 }]
             }]
         },
         'devname': 'tap920be2f4-2b',
         'address': '00:11:22:33:44:55',
         'id': iface_id,
         'type': network_model.VIF_TYPE_OVS
     }]
     with mock.patch('nova.utils.execute'):
         d = driver.DockerDriver(object)
         fake_inst = {'name': 'fake_instance', 'uuid': 'instance_uuid'}
         d.unplug_vifs(fake_inst, fake_net_info)
         mock_ui.assert_called_once_with(fake_inst, fake_net_info)
Exemplo n.º 3
0
    def test_plug_vifs_ovs(self):
        iface_id = '920be2f4-2b98-411e-890a-69bcabb2a5a0'
        calls = [
            mock.call('ip', 'link', 'add', 'name', 'tap920be2f4-2b',
                      'type', 'veth', 'peer', 'name', 'ns920be2f4-2b',
                      run_as_root=True),

            mock.call('ovs-vsctl', '--timeout=120', '--', '--if-exists',
                      'del-port', 'tap920be2f4-2b', '--', 'add-port',
                      'br-int', 'tap920be2f4-2b',
                      '--', 'set', 'Interface', 'tap920be2f4-2b',
                      'external-ids:iface-id=%s' % iface_id,
                      'external-ids:iface-status=active',
                      'external-ids:attached-mac=00:11:22:33:44:55',
                      'external-ids:vm-uuid=instance_uuid',
                      run_as_root=True),
            mock.call('ip', 'link', 'set', 'tap920be2f4-2b', 'up',
                      run_as_root=True),
        ]
        network_info = [
            {'network': {'bridge': 'br-int',
                         'subnets': [{'gateway': {'address': '10.11.12.1'},
                                      'cidr': '10.11.12.0/24',
                                      'ips': [{'address': '10.11.12.3',
                                               'type': 'fixed', 'version': 4}]
                                      }]},
             'address': '00:11:22:33:44:55',
             'id': iface_id,
             'type': network_model.VIF_TYPE_OVS}]
        with mock.patch('nova.utils.execute') as ex:
            driver = docker_driver.DockerDriver(object)
            driver.plug_vifs({'name': 'fake_instance',
                              'uuid': 'instance_uuid'}, network_info)
            ex.assert_has_calls(calls)
 def test_plug_vrouter(self):
     vid = '920be1f4-2b98-411e-890a-69bcabb2a5a0'
     address = '10.1.2.1'
     calls = [
         mock.call('ip',
                   'link',
                   'add',
                   'veth%s' % vid[:8],
                   'type',
                   'veth',
                   'peer',
                   'name',
                   'ns%s' % vid[:8],
                   run_as_root=True),
         mock.call('ip',
                   'link',
                   'set',
                   'ns%s' % vid[:8],
                   'address',
                   address,
                   run_as_root=True),
     ]
     network_info = [network_model.VIF(id=vid, address=address)]
     with mock.patch('nova.utils.execute') as ex:
         driver = docker_driver.DockerDriver(object)
         driver.plug_vifs({'name': 'fake_instance'}, network_info)
         ex.assert_has_calls(calls)
Exemplo n.º 5
0
 def test_unplug_vifs_iovisor(self):
     iface_id = '920be2f4-2b98-411e-890a-69bcabb2a5a0'
     tenant_id = 'tenant1'
     calls = [
         mock.call('ifc_ctl',
                   'gateway',
                   'ifdown',
                   'tap920be2f4-2b',
                   'access_vm',
                   'net1_' + iface_id,
                   '00:11:22:33:44:55',
                   run_as_root=True),
         mock.call('ifc_ctl',
                   'gateway',
                   'del_port',
                   'tap920be2f4-2b',
                   run_as_root=True)
     ]
     network_info = [self.vif_iovisor]
     with mock.patch('nova.utils.execute') as ex:
         driver = docker_driver.DockerDriver(object)
         driver.unplug_vifs(
             {
                 'name': 'fake_instance',
                 'uuid': 'instance_uuid',
                 'project_id': tenant_id
             }, network_info)
         ex.assert_has_calls(calls)
Exemplo n.º 6
0
    def test_plug_vifs_iovisor(self):
        iface_id = '920be2f4-2b98-411e-890a-69bcabb2a5a0'
        tenant_id = 'tenant1'
        calls = [
            mock.call('ip', 'link', 'add', 'name', 'tap920be2f4-2b', 'type',
                      'veth', 'peer', 'name', 'ns920be2f4-2b',
                      run_as_root=True),

            mock.call('ifc_ctl', 'gateway', 'add_port', 'tap920be2f4-2b',
                      run_as_root=True),

            mock.call('ifc_ctl', 'gateway', 'ifup', 'tap920be2f4-2b',
                      'access_vm', "net1_" + iface_id, '00:11:22:33:44:55',
                      'pgtag2=network-id-xxx-yyy-zzz',
                      'pgtag1=%s' % tenant_id, run_as_root=True),

            mock.call('ip', 'link', 'set', 'tap920be2f4-2b', 'up',
                      run_as_root=True),
        ]

        network_info = [self.vif_iovisor]

        with mock.patch('nova.utils.execute') as ex:
            driver = docker_driver.DockerDriver(object)
            driver.plug_vifs({'name': 'fake_instance',
                              'uuid': 'instance_uuid',
                              'project_id': tenant_id}, network_info)
            ex.assert_has_calls(calls)
Exemplo n.º 7
0
 def test_attach_vifs(self, mock_find_by_name, mock_find_pid):
     calls = [
         mock.call('ln', '-sf', '/proc/1234/ns/net',
                   '/var/run/netns/fake_id', run_as_root=True),
         mock.call('ip', 'link', 'set', 'ns920be2f4-2b', 'netns',
                   'fake_id', run_as_root=True),
         mock.call('ip', 'netns', 'exec', 'fake_id', 'ip', 'link',
                   'set', 'ns920be2f4-2b', 'address', '00:11:22:33:44:55',
                   run_as_root=True),
         mock.call('ip', 'netns', 'exec', 'fake_id',
                   'ip', 'addr', 'add', '10.11.12.3/24', 'dev',
                   'ns920be2f4-2b', run_as_root=True),
         mock.call('ip', 'netns', 'exec', 'fake_id',
                   'ip', 'link', 'set',
                   'ns920be2f4-2b', 'up', run_as_root=True),
         mock.call('ip', 'netns', 'exec', 'fake_id', 'ip', 'route',
                   'replace', 'default', 'via', '10.11.12.1', 'dev',
                   'ns920be2f4-2b', run_as_root=True)
     ]
     network_info = [
         {'network': {'bridge': 'br100',
                      'subnets': [{'gateway': {'address': '10.11.12.1'},
                                   'cidr': '10.11.12.0/24',
                                   'ips': [{'address': '10.11.12.3',
                                            'type': 'fixed', 'version': 4}]
                                   }]},
          'address': '00:11:22:33:44:55',
          'id': '920be2f4-2b98-411e-890a-69bcabb2a5a0',
          'type': network_model.VIF_TYPE_BRIDGE}]
     with mock.patch('nova.utils.execute') as ex:
         driver = docker_driver.DockerDriver(object)
         driver._attach_vifs({'name': 'fake_instance'}, network_info)
         ex.assert_has_calls(calls)
Exemplo n.º 8
0
 def test_attach_vrouter(self, mock_find_by_name, mock_find_pid):
     vid = '920be1f5-2b98-411e-890a-69bcabb2a5a0'
     address = '10.1.2.1'
     calls = [
         mock.call('mkdir', '-p', '/var/run/netns', run_as_root=True),
         mock.call('ln',
                   '-sf',
                   '/proc/7890/ns/net',
                   '/var/run/netns/my_vm',
                   run_as_root=True),
         mock.call('ip',
                   'link',
                   'set',
                   'ns%s' % vid[:8],
                   'netns',
                   'my_vm',
                   run_as_root=True),
         mock.call('ip',
                   'link',
                   'set',
                   'veth%s' % vid[:8],
                   'up',
                   run_as_root=True),
         mock.call('ip',
                   'netns',
                   'exec',
                   'my_vm',
                   'dhclient',
                   'ns%s' % vid[:8],
                   run_as_root=True),
     ]
     network_info = [
         network_model.VIF(
             id=vid,
             address=address,
             network=network_model.Network(
                 id='virtual-network-1',
                 subnets=[
                     network_model.Subnet(
                         cidr='1.1.1.0/24',
                         gateway=network_model.IP(address='1.1.1.254',
                                                  type='gateway'),
                         ips=[
                             network_model.IP(address='1.1.1.42',
                                              type='fixed',
                                              version=4)
                         ])
                 ]))
     ]
     instance = dict(name='fake_instance',
                     display_name='fake_vm',
                     hostname='fake_vm',
                     host='linux',
                     project_id='e2d2ddc6-4e0f-4cd4-b846-3bad53093ec6',
                     uuid='d4b817fb-7885-4649-bad7-89302dde12e1')
     with mock.patch('nova.utils.execute') as ex:
         driver = docker_driver.DockerDriver(object)
         driver._attach_vifs(instance, network_info)
         ex.assert_has_calls(calls)
Exemplo n.º 9
0
    def test_plug_vifs_ovs_hybrid(self):
        iface_id = '920be2f4-2b98-411e-890a-69bcabb2a5a0'
        calls = [
            mock.call('brctl', 'addbr', 'qbr920be2f4-2b', run_as_root=True),

            mock.call('brctl', 'setfd', 'qbr920be2f4-2b', 0, run_as_root=True),
            mock.call('brctl', 'stp', 'qbr920be2f4-2b', 'off',
                      run_as_root=True),
            mock.call('tee', "/sys/class/net/qbr920be2f4-2b/bridge/multicast_"
                      "snooping", run_as_root=True, process_input='0',
                      check_exit_code=[0, 1]),
            mock.call('ip', 'link', 'add', 'qvb920be2f4-2b', 'type',
                      'veth', 'peer', 'name', 'qvo920be2f4-2b',
                      run_as_root=True),
            mock.call('ip', 'link', 'set', 'qvb920be2f4-2b', 'up',
                      run_as_root=True),
            mock.call('ip', 'link', 'set', 'qvb920be2f4-2b', 'promisc', 'on',
                      run_as_root=True),
            mock.call('ip', 'link', 'set', 'qvo920be2f4-2b', 'up',
                      run_as_root=True),
            mock.call('ip', 'link', 'set', 'qvo920be2f4-2b', 'promisc', 'on',
                      run_as_root=True),
            mock.call('ip', 'link', 'set', 'qbr920be2f4-2b', 'up',
                      run_as_root=True),
            mock.call('brctl', 'addif', 'qbr920be2f4-2b', 'qvb920be2f4-2b',
                      run_as_root=True),
            mock.call('ovs-vsctl', '--timeout=120', '--', '--if-exists',
                      'del-port', 'qvo920be2f4-2b', '--', 'add-port',
                      'br-int', 'qvo920be2f4-2b', '--', 'set', 'Interface',
                      'qvo920be2f4-2b', "external-ids:iface-id=920be2f4-2b98-"
                      "411e-890a-69bcabb2a5a0",
                      'external-ids:iface-status=active',
                      'external-ids:attached-mac=00:11:22:33:44:55',
                      'external-ids:vm-uuid=instance_uuid', run_as_root=True),
            mock.call('ip', 'link', 'add', 'name', 'tap920be2f4-2b', 'type',
                      'veth', 'peer', 'name', 'ns920be2f4-2b',
                      run_as_root=True),
            mock.call('brctl', 'addif', 'qbr920be2f4-2b', 'tap920be2f4-2b',
                      run_as_root=True),
            mock.call('ip', 'link', 'set', 'tap920be2f4-2b', 'up',
                      run_as_root=True),
        ]
        network_info = [
            {'network': {'bridge': 'br-int',
                         'subnets': [{'gateway': {'address': '10.11.12.1'},
                                      'cidr': '10.11.12.0/24',
                                      'ips': [{'address': '10.11.12.3',
                                               'type': 'fixed', 'version': 4}]
                                      }]},
             'address': '00:11:22:33:44:55',
             'id': iface_id,
             'details': {'port_filter': True, 'ovs_hybrid_plug': True},
             'type': network_model.VIF_TYPE_OVS}]
        with mock.patch('nova.utils.execute') as ex:
            driver = docker_driver.DockerDriver(object)
            driver.plug_vifs({'name': 'fake_instance',
                              'uuid': 'instance_uuid'}, network_info)
            ex.assert_has_calls(calls)
 def test_plug_vifs_bridge(self, mock_aif, mock_sbf, mock_pif):
     fake_net_info = [self.vif_bridge]
     with mock.patch('nova.utils.execute'):
         d = driver.DockerDriver(object)
         fake_inst = {'name': 'fake_instance'}
         d.plug_vifs(fake_inst, fake_net_info)
         mock_aif.assert_called_once_with(fake_inst, fake_net_info)
         mock_sbf.assert_called_once_with(fake_inst, fake_net_info)
         mock_pif.assert_called_once_with(fake_inst, fake_net_info)
Exemplo n.º 11
0
 def test_unplug_vifs_midonet(self):
     iface_id = '920be2f4-2b98-411e-890a-69bcabb2a5a0'
     calls = [
         mock.call('mm-ctl', '--unbind-port', iface_id, run_as_root=True)
     ]
     network_info = [{'id': iface_id,
                      'type': network_model.VIF_TYPE_MIDONET}]
     with mock.patch('nova.utils.execute') as ex:
         driver = docker_driver.DockerDriver(object)
         driver.unplug_vifs({'name': 'fake_instance',
                             'uuid': 'instance_uuid'}, network_info)
         ex.assert_has_calls(calls)
 def test_plug_two_vrouters(self):
     vid1 = '921be2f4-2b98-411e-890a-69bcabb2a5a1'
     address1 = '10.1.2.2'
     vid2 = '922be3f4-2b98-411e-890a-69bcabb2a5a2'
     address2 = '10.1.2.3'
     calls = [
         mock.call('ip',
                   'link',
                   'add',
                   'veth%s' % vid1[:8],
                   'type',
                   'veth',
                   'peer',
                   'name',
                   'ns%s' % vid1[:8],
                   run_as_root=True),
         mock.call('ip',
                   'link',
                   'set',
                   'ns%s' % vid1[:8],
                   'address',
                   address1,
                   run_as_root=True),
         mock.call('ip',
                   'link',
                   'add',
                   'veth%s' % vid2[:8],
                   'type',
                   'veth',
                   'peer',
                   'name',
                   'ns%s' % vid2[:8],
                   run_as_root=True),
         mock.call('ip',
                   'link',
                   'set',
                   'ns%s' % vid2[:8],
                   'address',
                   address2,
                   run_as_root=True),
     ]
     network_info = [
         network_model.VIF(id=vid1, address=address1),
         network_model.VIF(id=vid2, address=address2)
     ]
     with mock.patch('nova.utils.execute') as ex:
         driver = docker_driver.DockerDriver(object)
         driver.plug_vifs({'name': 'fake_instance'}, network_info)
         ex.assert_has_calls(calls)
Exemplo n.º 13
0
 def test_unplug_vifs_ovs_hybrid(self):
     iface_id = '920be2f4-2b98-411e-890a-69bcabb2a5a0'
     calls = [
         mock.call('ovs-vsctl',
                   '--timeout=120',
                   '--',
                   '--if-exists',
                   'del-port',
                   'br-int',
                   'qvo920be2f4-2b',
                   run_as_root=True)
     ]
     network_info = [{
         'network': {
             'bridge':
             'br-int',
             'subnets': [{
                 'gateway': {
                     'address': '10.11.12.1'
                 },
                 'cidr':
                 '10.11.12.0/24',
                 'ips': [{
                     'address': '10.11.12.3',
                     'type': 'fixed',
                     'version': 4
                 }]
             }]
         },
         'devname': 'tap920be2f4-2b',
         'address': '00:11:22:33:44:55',
         'id': iface_id,
         'details': {
             'port_filter': True,
             'ovs_hybrid_plug': True
         },
         'type': network_model.VIF_TYPE_OVS
     }]
     with mock.patch('nova.utils.execute') as ex:
         driver = docker_driver.DockerDriver(object)
         driver.unplug_vifs(
             {
                 'name': 'fake_instance',
                 'uuid': 'instance_uuid'
             }, network_info)
         ex.assert_has_calls(calls)
Exemplo n.º 14
0
    def test_plug_vifs_midonet(self):
        iface_id = '920be2f4-2b98-411e-890a-69bcabb2a5a0'
        host_side_veth = 'tap920be2f4-2b'
        calls = [
            mock.call('ip',
                      'link',
                      'add',
                      'name',
                      host_side_veth,
                      'type',
                      'veth',
                      'peer',
                      'name',
                      'ns920be2f4-2b',
                      run_as_root=True),
            mock.call('ip',
                      'link',
                      'set',
                      host_side_veth,
                      'up',
                      run_as_root=True),
            mock.call('mm-ctl',
                      '--bind-port',
                      iface_id,
                      host_side_veth,
                      run_as_root=True),
        ]

        network_info = [{
            'id': iface_id,
            'type': network_model.VIF_TYPE_MIDONET
        }]

        with mock.patch('nova.utils.execute') as ex:
            driver = docker_driver.DockerDriver(object)
            driver.plug_vifs({
                'name': 'fake_instance',
                'uuid': 'instance_uuid'
            }, network_info)
            ex.assert_has_calls(calls)
Exemplo n.º 15
0
 def test_get_dns_entries(self):
     driver = docker_driver.DockerDriver(object)
     network_info = utils.get_test_network_info()
     self.assertEqual(['0.0.0.0', '0.0.0.0'],
                      driver._extract_dns_entries(network_info))
 def setUp(self):
     super(DockerFirewallDriverTestCase, self).setUp()
     self.driver = driver.DockerDriver(None)
Exemplo n.º 17
0
 def test_unplug_vrouter(self):
     vid = '920be1f4-2b98-411e-890a-69bcabb2a5a0'
     address = '10.1.2.1'
     network_info = [network_model.VIF(id=vid, address=address)]
     driver = docker_driver.DockerDriver(object)
     driver.unplug_vifs({'name': 'fake_instance'}, network_info)