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)
Exemplo n.º 2
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)
    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)
    def test_network_is_removed(self):
        tenant_id = 'test'
        network_id = '123'

        db.remember_network(tenant_id, network_id, '123')
        db.forget_network(tenant_id, network_id)
        net_provisioned = db.is_network_provisioned(tenant_id, network_id)
        self.assertFalse(net_provisioned, 'The network should be deleted')
Exemplo n.º 5
0
    def test_network_is_removed(self):
        tenant_id = 'test'
        network_id = '123'

        db.remember_network(tenant_id, network_id, '123')
        db.forget_network(tenant_id, network_id)
        net_provisioned = db.is_network_provisioned(tenant_id, network_id)
        self.assertFalse(net_provisioned, 'The network should be deleted')
    def test_network_is_removed(self):
        tenant_id = "test"
        network_id = "123"

        db.remember_network(tenant_id, network_id, "123")
        db.forget_network(tenant_id, network_id)
        net_provisioned = db.is_network_provisioned(tenant_id, network_id)
        self.assertFalse(net_provisioned, "The network should be deleted")
Exemplo n.º 7
0
 def delete_network_precommit(self, context):
     """Delete the network infromation from the DB."""
     network = context.current
     network_id = network['id']
     tenant_id = network['tenant_id']
     with self.eos_sync_lock:
         if db.is_network_provisioned(tenant_id, network_id):
             db.forget_network(tenant_id, network_id)
         # if necessary, delete tenant as well.
         self.delete_tenant(tenant_id)
Exemplo n.º 8
0
 def delete_network_precommit(self, context):
     """Delete the network infromation from the DB."""
     network = context.current
     network_id = network['id']
     tenant_id = network['tenant_id']
     with self.eos_sync_lock:
         if db.is_network_provisioned(tenant_id, network_id):
             db.forget_network(tenant_id, network_id)
         # if necessary, delete tenant as well.
         self.delete_tenant(tenant_id)
Exemplo n.º 9
0
 def _cleanup_db(self):
     """Clean up any uncessary entries in our DB."""
     db_tenants = db.get_tenants()
     for tenant in db_tenants:
         neutron_nets = self.ndb.get_all_networks_for_tenant(tenant)
         neutron_nets_id = []
         for net in neutron_nets:
             neutron_nets_id.append(net['id'])
         db_nets = db.get_networks(tenant)
         for net_id in db_nets.keys():
             if net_id not in neutron_nets_id:
                 db.forget_network(tenant, net_id)
Exemplo n.º 10
0
 def _cleanup_db(self):
     """Clean up any uncessary entries in our DB."""
     db_tenants = db.get_tenants()
     for tenant in db_tenants:
         neutron_nets = self.ndb.get_all_networks_for_tenant(tenant)
         neutron_nets_id = []
         for net in neutron_nets:
             neutron_nets_id.append(net['id'])
         db_nets = db.get_networks(tenant)
         for net_id in db_nets.keys():
             if net_id not in neutron_nets_id:
                 db.forget_network(tenant, net_id)
    def test_removes_all_networks(self):
        tenant_id = 'test'
        num_nets = 100
        old_nets = db.num_nets_provisioned(tenant_id)
        nets = ['id_%s' % n for n in range(num_nets)]
        for net_id in nets:
            db.remember_network(tenant_id, net_id, 123)
        for net_id in nets:
            db.forget_network(tenant_id, net_id)

        num_nets_provisioned = db.num_nets_provisioned(tenant_id)
        expected = old_nets
        self.assertEqual(expected, num_nets_provisioned,
                         'There should be %d nets, not %d' %
                         (expected, num_nets_provisioned))
Exemplo n.º 12
0
    def test_removes_all_networks(self):
        tenant_id = 'test'
        num_nets = 100
        old_nets = db.num_nets_provisioned(tenant_id)
        nets = ['id_%s' % n for n in range(num_nets)]
        for net_id in nets:
            db.remember_network(tenant_id, net_id, 123)
        for net_id in nets:
            db.forget_network(tenant_id, net_id)

        num_nets_provisioned = db.num_nets_provisioned(tenant_id)
        expected = old_nets
        self.assertEqual(expected, num_nets_provisioned,
                         'There should be %d nets, not %d' %
                         (expected, num_nets_provisioned))
Exemplo n.º 13
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)
Exemplo n.º 15
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)
    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)