Пример #1
0
    def test_synchronize_one_network(self):
        """Test to ensure that only the required resources are sent to EOS."""

        # Store two tenants in a db and a single tenant in EOS.
        # The sync should send details of the second tenant to EOS
        tenant_1_id = 'tenant-1'
        tenant_1_net_1_id = 'ten-1-net-1'
        tenant_1_net_1_seg_id = 11
        db.remember_tenant(tenant_1_id)
        db.remember_network(tenant_1_id, tenant_1_net_1_id,
                            tenant_1_net_1_seg_id)

        tenant_2_id = 'tenant-2'
        tenant_2_net_1_id = 'ten-2-net-1'
        tenant_2_net_1_seg_id = 21
        db.remember_tenant(tenant_2_id)
        db.remember_network(tenant_2_id, tenant_2_net_1_id,
                            tenant_2_net_1_seg_id)

        self.rpc.get_tenants.return_value = {
            tenant_1_id: {
                'tenantVmInstances': {},
                'tenantNetworks': {
                    tenant_1_net_1_id: {
                        'networkId': tenant_1_net_1_id,
                        'networkName': 'Net1',
                        'segmenationType': 'vlan',
                        'segmentationTypeId': tenant_1_net_1_seg_id,
                    }
                }
            }
        }

        self.sync_service.do_synchronize()

        expected_calls = [
            mock.call.get_region_updated_time(),
            mock.call._run_openstack_cmds(['sync start']),
            mock.call.register_with_eos(),
            mock.call.get_tenants(),
            mock.call.create_network_bulk(
                tenant_2_id,
                [{'network_id': tenant_2_net_1_id,
                  'segmentation_id': tenant_2_net_1_seg_id,
                  'network_name': ''}]),
            mock.call._run_openstack_cmds(['sync end']),
            mock.call.get_region_updated_time()
        ]

        self.assertTrue(self.rpc.mock_calls == expected_calls,
                        "Seen: %s\nExpected: %s" % (
                            self.rpc.mock_calls,
                            expected_calls,
                        )
                        )

        db.forget_network(tenant_1_id, tenant_1_net_1_id)
        db.forget_network(tenant_2_id, tenant_2_net_1_id)
        db.forget_tenant(tenant_1_id)
        db.forget_tenant(tenant_2_id)
Пример #2
0
    def create_port_precommit(self, context):
        """Remember the infromation about a VM and its ports

        A VM information, along with the physical host information
        is saved.
        """
        port = context.current
        device_id = port['device_id']
        device_owner = port['device_owner']
        host = context.host

        # device_id and device_owner are set on VM boot
        is_vm_boot = device_id and device_owner
        if host and is_vm_boot:
            port_id = port['id']
            network_id = port['network_id']
            tenant_id = port['tenant_id']
            if not tenant_id:
                tenant_id = context._plugin_context.tenant_id
            with self.eos_sync_lock:
                if not db.is_network_provisioned(tenant_id, network_id):
                    # Ignore this request if network is not provisioned
                    return
                db.remember_tenant(tenant_id)
                db.remember_vm(device_id, host, port_id, network_id, tenant_id)
Пример #3
0
    def test_tenant_is_removed(self):
        tenant_id = 'test'

        db.remember_tenant(tenant_id)
        db.forget_tenant(tenant_id)
        net_provisioned = db.is_tenant_provisioned(tenant_id)
        self.assertFalse(net_provisioned, 'The Tenant should be deleted')
Пример #4
0
    def create_port_precommit(self, context):
        """Remember the infromation about a VM and its ports

        A VM information, along with the physical host information
        is saved.
        """
        port = context.current
        device_id = port['device_id']
        device_owner = port['device_owner']
        host = context.host

        # device_id and device_owner are set on VM boot
        is_vm_boot = device_id and device_owner
        if host and is_vm_boot:
            port_id = port['id']
            network_id = port['network_id']
            tenant_id = port['tenant_id']
            if not tenant_id:
                tenant_id = context._plugin_context.tenant_id
            with self.eos_sync_lock:
                if not db.is_network_provisioned(tenant_id, network_id):
                    # Ignore this request if network is not provisioned
                    return
                db.remember_tenant(tenant_id)
                db.remember_vm(device_id, host, port_id,
                               network_id, tenant_id)
    def test_synchronize_required(self):
        """Tests whether synchronize() sends the right commands.

           This test verifies a scenario when the sync is required.
        """
        region_updated_time = {"regionName": "RegionOne", "regionTimestamp": "12345"}
        self.rpc.get_region_updated_time.return_value = region_updated_time
        self.sync_service._region_updated_time = {"regionName": "RegionOne", "regionTimestamp": "0"}

        tenant_id = "tenant-1"
        network_id = "net-1"
        segmentation_id = 42
        db.remember_tenant(tenant_id)
        db.remember_network(tenant_id, network_id, segmentation_id)

        self.rpc.get_tenants.return_value = {}

        self.sync_service.do_synchronize()

        expected_calls = [
            mock.call.get_region_updated_time(),
            mock.call._run_openstack_cmds(["sync start"]),
            mock.call.register_with_eos(),
            mock.call.get_tenants(),
            mock.call.create_network_bulk(
                tenant_id, [{"network_id": network_id, "segmentation_id": segmentation_id, "network_name": ""}]
            ),
            mock.call._run_openstack_cmds(["sync end"]),
            mock.call.get_region_updated_time(),
        ]
        assert self.rpc.mock_calls == expected_calls

        db.forget_network(tenant_id, network_id)
        db.forget_tenant(tenant_id)
    def test_tenant_is_removed(self):
        tenant_id = 'test'

        db.remember_tenant(tenant_id)
        db.forget_tenant(tenant_id)
        net_provisioned = db.is_tenant_provisioned(tenant_id)
        self.assertFalse(net_provisioned, 'The Tenant should be deleted')
    def test_synchronize_one_network(self):
        """Test to ensure that only the required resources are sent to EOS."""

        # Store two tenants in a db and a single tenant in EOS.
        # The sync should send details of the second tenant to EOS
        tenant_1_id = 'tenant-1'
        tenant_1_net_1_id = 'ten-1-net-1'
        tenant_1_net_1_seg_id = 11
        db.remember_tenant(tenant_1_id)
        db.remember_network(tenant_1_id, tenant_1_net_1_id,
                            tenant_1_net_1_seg_id)

        tenant_2_id = 'tenant-2'
        tenant_2_net_1_id = 'ten-2-net-1'
        tenant_2_net_1_seg_id = 21
        db.remember_tenant(tenant_2_id)
        db.remember_network(tenant_2_id, tenant_2_net_1_id,
                            tenant_2_net_1_seg_id)

        self.rpc.get_tenants.return_value = {
            tenant_1_id: {
                'tenantVmInstances': {},
                'tenantNetworks': {
                    tenant_1_net_1_id: {
                        'networkId': tenant_1_net_1_id,
                        'networkName': 'Net1',
                        'segmenationType': 'vlan',
                        'segmentationTypeId': tenant_1_net_1_seg_id,
                    }
                }
            }
        }

        self.sync_service.do_synchronize()

        expected_calls = [
            mock.call.get_region_updated_time(),
            mock.call._run_openstack_cmds(['sync start']),
            mock.call.register_with_eos(),
            mock.call.get_tenants(),
            mock.call.create_network_bulk(tenant_2_id, [{
                'network_id': tenant_2_net_1_id,
                'segmentation_id': tenant_2_net_1_seg_id,
                'network_name': ''
            }]),
            mock.call._run_openstack_cmds(['sync end']),
            mock.call.get_region_updated_time()
        ]

        self.assertTrue(
            self.rpc.mock_calls == expected_calls, "Seen: %s\nExpected: %s" % (
                self.rpc.mock_calls,
                expected_calls,
            ))

        db.forget_network(tenant_1_id, tenant_1_net_1_id)
        db.forget_network(tenant_2_id, tenant_2_net_1_id)
        db.forget_tenant(tenant_1_id)
        db.forget_tenant(tenant_2_id)
Пример #8
0
    def test_remembers_multiple_tenants(self):
        expected_num_tenants = 100
        tenants = ['id%s' % n for n in range(expected_num_tenants)]
        for tenant_id in tenants:
            db.remember_tenant(tenant_id)

        num_tenants_provisioned = db.num_provisioned_tenants()
        self.assertEqual(expected_num_tenants, num_tenants_provisioned,
                         'There should be %d tenants, not %d' %
                         (expected_num_tenants, num_tenants_provisioned))
    def test_remembers_multiple_tenants(self):
        expected_num_tenants = 100
        tenants = ['id%s' % n for n in range(expected_num_tenants)]
        for tenant_id in tenants:
            db.remember_tenant(tenant_id)

        num_tenants_provisioned = db.num_provisioned_tenants()
        self.assertEqual(expected_num_tenants, num_tenants_provisioned,
                         'There should be %d tenants, not %d' %
                         (expected_num_tenants, num_tenants_provisioned))
Пример #10
0
    def create_network_precommit(self, context):
        """Remember the tenant, and network information."""

        network = context.current
        segments = context.network_segments
        network_id = network['id']
        tenant_id = network['tenant_id']
        segmentation_id = segments[0]['segmentation_id']
        with self.eos_sync_lock:
            db.remember_tenant(tenant_id)
            db.remember_network(tenant_id, network_id, segmentation_id)
Пример #11
0
    def create_network_precommit(self, context):
        """Remember the tenant, and network information."""

        network = context.current
        segments = context.network_segments
        network_id = network['id']
        tenant_id = network['tenant_id']
        segmentation_id = segments[0]['segmentation_id']
        with self.eos_sync_lock:
            db.remember_tenant(tenant_id)
            db.remember_network(tenant_id,
                                network_id,
                                segmentation_id)
    def test_removes_multiple_tenants(self):
        num_tenants = 100
        tenants = ["id%s" % n for n in range(num_tenants)]
        for tenant_id in tenants:
            db.remember_tenant(tenant_id)
        for tenant_id in tenants:
            db.forget_tenant(tenant_id)

        num_tenants_provisioned = db.num_provisioned_tenants()
        expected = 0
        self.assertEqual(
            expected,
            num_tenants_provisioned,
            "There should be %d tenants, not %d" % (expected, num_tenants_provisioned),
        )
Пример #13
0
    def create_network_precommit(self, context):
        """Remember the tenant, and network information."""

        network = context.current
        segments = context.network_segments
        if segments[0][driver_api.NETWORK_TYPE] != p_const.TYPE_VLAN:
            # If network type is not VLAN, do nothing
            return
        network_id = network['id']
        tenant_id = network['tenant_id']
        if not tenant_id:
            tenant_id = context._plugin_context.tenant_id
        segmentation_id = segments[0]['segmentation_id']
        with self.eos_sync_lock:
            db.remember_tenant(tenant_id)
            db.remember_network(tenant_id, network_id, segmentation_id)
Пример #14
0
    def create_network_precommit(self, context):
        """Remember the tenant, and network information."""

        network = context.current
        segments = context.network_segments
        if segments[0][driver_api.NETWORK_TYPE] != p_const.TYPE_VLAN:
            # If network type is not VLAN, do nothing
            return
        network_id = network['id']
        tenant_id = network['tenant_id']
        if not tenant_id:
            tenant_id = context._plugin_context.tenant_id
        segmentation_id = segments[0]['segmentation_id']
        with self.eos_sync_lock:
            db.remember_tenant(tenant_id)
            db.remember_network(tenant_id,
                                network_id,
                                segmentation_id)
Пример #15
0
    def test_synchronize_required(self):
        """Tests whether synchronize() sends the right commands.

           This test verifies a scenario when the sync is required.
        """
        region_updated_time = {
            'regionName': 'RegionOne',
            'regionTimestamp': '12345'
        }
        self.rpc.get_region_updated_time.return_value = region_updated_time
        self.sync_service._region_updated_time = {
            'regionName': 'RegionOne',
            'regionTimestamp': '0',
        }

        tenant_id = 'tenant-1'
        network_id = 'net-1'
        segmentation_id = 42
        db.remember_tenant(tenant_id)
        db.remember_network(tenant_id, network_id, segmentation_id)

        self.rpc.get_tenants.return_value = {}

        self.sync_service.do_synchronize()

        expected_calls = [
            mock.call.get_region_updated_time(),
            mock.call._run_openstack_cmds(['sync start']),
            mock.call.register_with_eos(),
            mock.call.get_tenants(),
            mock.call.create_network_bulk(
                tenant_id,
                [{'network_id': network_id,
                  'segmentation_id': segmentation_id,
                  'network_name': ''}]),
            mock.call._run_openstack_cmds(['sync end']),
            mock.call.get_region_updated_time()
        ]
        assert self.rpc.mock_calls == expected_calls

        db.forget_network(tenant_id, network_id)
        db.forget_tenant(tenant_id)
    def test_synchronize_required(self):
        """Tests whether synchronize() sends the right commands.

           This test verifies a scenario when the sync is required.
        """
        region_updated_time = {
            'regionName': 'RegionOne',
            'regionTimestamp': '12345'
        }
        self.rpc.get_region_updated_time.return_value = region_updated_time
        self.sync_service._region_updated_time = {
            'regionName': 'RegionOne',
            'regionTimestamp': '0',
        }

        tenant_id = 'tenant-1'
        network_id = 'net-1'
        segmentation_id = 42
        db.remember_tenant(tenant_id)
        db.remember_network(tenant_id, network_id, segmentation_id)

        self.rpc.get_tenants.return_value = {}

        self.sync_service.do_synchronize()

        expected_calls = [
            mock.call.get_region_updated_time(),
            mock.call._run_openstack_cmds(['sync start']),
            mock.call.register_with_eos(),
            mock.call.get_tenants(),
            mock.call.create_network_bulk(tenant_id, [{
                'network_id': network_id,
                'segmentation_id': segmentation_id,
                'network_name': ''
            }]),
            mock.call._run_openstack_cmds(['sync end']),
            mock.call.get_region_updated_time()
        ]
        assert self.rpc.mock_calls == expected_calls

        db.forget_network(tenant_id, network_id)
        db.forget_tenant(tenant_id)
Пример #17
0
    def create_port_precommit(self, context):
        """Remember the infromation about a VM and its ports

        A VM information, along with the physical host information
        is saved.
        """
        port = context.current
        device_id = port['device_id']
        device_owner = port['device_owner']
        host = context.host

        # device_id and device_owner are set on VM boot
        is_vm_boot = device_id and device_owner
        if host and is_vm_boot:
            port_id = port['id']
            network_id = port['network_id']
            tenant_id = port['tenant_id']
            with self.eos_sync_lock:
                db.remember_tenant(tenant_id)
                db.remember_vm(device_id, host, port_id, network_id, tenant_id)
Пример #18
0
    def test_tenant_is_remembered(self):
        tenant_id = 'test'

        db.remember_tenant(tenant_id)
        net_provisioned = db.is_tenant_provisioned(tenant_id)
        self.assertTrue(net_provisioned, 'Tenant must be provisioned')
    def test_tenant_is_remembered(self):
        tenant_id = 'test'

        db.remember_tenant(tenant_id)
        net_provisioned = db.is_tenant_provisioned(tenant_id)
        self.assertTrue(net_provisioned, 'Tenant must be provisioned')
    def test_synchronize_all_networks(self):
        """Test to ensure that only the required resources are sent to EOS."""

        # Store two tenants in a db and none on EOS.
        # The sync should send details of all tenants to EOS
        tenant_1_id = u'tenant-1'
        tenant_1_net_1_id = u'ten-1-net-1'
        tenant_1_net_1_seg_id = 11
        db.remember_tenant(tenant_1_id)
        db.remember_network(tenant_1_id, tenant_1_net_1_id,
                            tenant_1_net_1_seg_id)

        tenant_2_id = u'tenant-2'
        tenant_2_net_1_id = u'ten-2-net-1'
        tenant_2_net_1_seg_id = 21
        db.remember_tenant(tenant_2_id)
        db.remember_network(tenant_2_id, tenant_2_net_1_id,
                            tenant_2_net_1_seg_id)

        self.rpc.get_tenants.return_value = {}

        self.sync_service.do_synchronize()

        expected_calls = [
            mock.call.get_region_updated_time(),
            mock.call._run_openstack_cmds(['sync start']),
            mock.call.register_with_eos(),
            mock.call.get_tenants(),
            mock.call.create_network_bulk(tenant_1_id, [{
                'network_id': tenant_1_net_1_id,
                'segmentation_id': tenant_1_net_1_seg_id,
                'network_name': ''
            }]),
            mock.call.create_network_bulk(tenant_2_id, [{
                'network_id': tenant_2_net_1_id,
                'segmentation_id': tenant_2_net_1_seg_id,
                'network_name': ''
            }]),
            mock.call._run_openstack_cmds(['sync end']),
            mock.call.get_region_updated_time()
        ]

        # The create_network_bulk() can be called in different order. So split
        # it up. The first part checks if the initial set of methods are
        # invoked.
        self.assertTrue(
            self.rpc.mock_calls[:4] == expected_calls[:4],
            "Seen: %s\nExpected: %s" % (
                self.rpc.mock_calls,
                expected_calls,
            ))
        # Check if tenant 1 networks are created. It must be one of the two
        # methods.
        self.assertTrue(
            self.rpc.mock_calls[4] in expected_calls[4:6],
            "Seen: %s\nExpected: %s" % (
                self.rpc.mock_calls,
                expected_calls,
            ))
        # Check if tenant 2 networks are created. It must be one of the two
        # methods.
        self.assertTrue(
            self.rpc.mock_calls[5] in expected_calls[4:6],
            "Seen: %s\nExpected: %s" % (
                self.rpc.mock_calls,
                expected_calls,
            ))
        # Check if the sync end methods are invoked.
        self.assertTrue(
            self.rpc.mock_calls[6:8] == expected_calls[6:8],
            "Seen: %s\nExpected: %s" % (
                self.rpc.mock_calls,
                expected_calls,
            ))

        db.forget_network(tenant_1_id, tenant_1_net_1_id)
        db.forget_network(tenant_2_id, tenant_2_net_1_id)
        db.forget_tenant(tenant_1_id)
        db.forget_tenant(tenant_2_id)
Пример #21
0
    def test_synchronize_all_networks(self):
        """Test to ensure that only the required resources are sent to EOS."""

        # Store two tenants in a db and none on EOS.
        # The sync should send details of all tenants to EOS
        tenant_1_id = u'tenant-1'
        tenant_1_net_1_id = u'ten-1-net-1'
        tenant_1_net_1_seg_id = 11
        db.remember_tenant(tenant_1_id)
        db.remember_network(tenant_1_id, tenant_1_net_1_id,
                            tenant_1_net_1_seg_id)

        tenant_2_id = u'tenant-2'
        tenant_2_net_1_id = u'ten-2-net-1'
        tenant_2_net_1_seg_id = 21
        db.remember_tenant(tenant_2_id)
        db.remember_network(tenant_2_id, tenant_2_net_1_id,
                            tenant_2_net_1_seg_id)

        self.rpc.get_tenants.return_value = {}

        self.sync_service.do_synchronize()

        expected_calls = [
            mock.call.get_region_updated_time(),
            mock.call._run_openstack_cmds(['sync start']),
            mock.call.register_with_eos(),
            mock.call.get_tenants(),
            mock.call.create_network_bulk(
                tenant_1_id,
                [{'network_id': tenant_1_net_1_id,
                  'segmentation_id': tenant_1_net_1_seg_id,
                  'network_name': ''}]),
            mock.call.create_network_bulk(
                tenant_2_id,
                [{'network_id': tenant_2_net_1_id,
                  'segmentation_id': tenant_2_net_1_seg_id,
                  'network_name': ''}]),
            mock.call._run_openstack_cmds(['sync end']),
            mock.call.get_region_updated_time()
        ]

        # The create_network_bulk() can be called in different order. So split
        # it up. The first part checks if the initial set of methods are
        # invoked.
        self.assertTrue(self.rpc.mock_calls[:4] == expected_calls[:4],
                        "Seen: %s\nExpected: %s" % (
                            self.rpc.mock_calls,
                            expected_calls,
                        )
                        )
        # Check if tenant 1 networks are created. It must be one of the two
        # methods.
        self.assertTrue(self.rpc.mock_calls[4] in expected_calls[4:6],
                        "Seen: %s\nExpected: %s" % (
                            self.rpc.mock_calls,
                            expected_calls,
                        )
                        )
        # Check if tenant 2 networks are created. It must be one of the two
        # methods.
        self.assertTrue(self.rpc.mock_calls[5] in expected_calls[4:6],
                        "Seen: %s\nExpected: %s" % (
                            self.rpc.mock_calls,
                            expected_calls,
                        )
                        )
        # Check if the sync end methods are invoked.
        self.assertTrue(self.rpc.mock_calls[6:8] == expected_calls[6:8],
                        "Seen: %s\nExpected: %s" % (
                            self.rpc.mock_calls,
                            expected_calls,
                        )
                        )

        db.forget_network(tenant_1_id, tenant_1_net_1_id)
        db.forget_network(tenant_2_id, tenant_2_net_1_id)
        db.forget_tenant(tenant_1_id)
        db.forget_tenant(tenant_2_id)