Esempio n. 1
0
    def test__rbacSync_syncs_all_on_conflict(self):
        RBACLastSync.objects.create(
            resource_type='resource-pool', sync_id='a-b-c')
        RBACSync.objects.clear('resource-pool')
        _, resources = self.make_resource_pools()
        reasons = [
            sync.source
            for sync in RBACSync.objects.changes('resource-pool')
        ]

        rbac_client = MagicMock()
        rbac_client.update_resources.side_effect = [
            SyncConflictError(),
            'x-y-z',
        ]
        service = RegionControllerService(sentinel.listener)
        self.patch(service, '_getRBACClient').return_value = rbac_client
        service.rbacInit = True

        self.assertEquals(reasons, service._rbacSync())
        self.assertThat(
            rbac_client.update_resources,
            MockCallsMatch(
                call(
                    'resource-pool',
                    updates=resources[1:], removals=set(),
                    last_sync_id='a-b-c'),
                call('resource-pool', updates=resources)))
        self.assertFalse(RBACSync.objects.exists())
        last_sync = RBACLastSync.objects.get()
        self.assertEqual(last_sync.resource_type, 'resource-pool')
        self.assertEqual(last_sync.sync_id, 'x-y-z')
Esempio n. 2
0
    def test_rbacSync_syncs_on_changes(self):
        RBACLastSync.objects.create(resource_type="resource-pool",
                                    sync_id="a-b-c")
        RBACSync.objects.clear("resource-pool")
        _, resources = self.make_resource_pools()
        reasons = [
            sync.source for sync in RBACSync.objects.changes("resource-pool")
        ]

        rbac_client = MagicMock()
        rbac_client.update_resources.return_value = "x-y-z"
        service = RegionControllerService(sentinel.listener)
        self.patch(service, "_getRBACClient").return_value = rbac_client
        service.rbacInit = True

        self.assertEqual(reasons, service._rbacSync())
        self.assertThat(
            rbac_client.update_resources,
            MockCalledOnceWith(
                "resource-pool",
                updates=resources[1:],
                removals=set(),
                last_sync_id="a-b-c",
            ),
        )
        self.assertFalse(RBACSync.objects.exists())
        last_sync = RBACLastSync.objects.get()
        self.assertEqual(last_sync.resource_type, "resource-pool")
        self.assertEqual(last_sync.sync_id, "x-y-z")
Esempio n. 3
0
    def test__rbacSync_update_sync_id(self):
        rbac_sync = RBACLastSync.objects.create(
            resource_type='resource-pool', sync_id='a-b-c')
        RBACSync.objects.clear('resource-pool')
        _, resources = self.make_resource_pools()

        rbac_client = MagicMock()
        rbac_client.update_resources.return_value = 'x-y-z'
        service = RegionControllerService(sentinel.listener)
        self.patch(service, '_getRBACClient').return_value = rbac_client
        service.rbacInit = True

        service._rbacSync()
        last_sync = RBACLastSync.objects.get()
        self.assertEqual(rbac_sync.id, last_sync.id)
        self.assertEqual(last_sync.resource_type, 'resource-pool')
        self.assertEqual(last_sync.sync_id, 'x-y-z')
Esempio n. 4
0
    def test__rbacSync_syncs_on_changes(self):
        RBACSync.objects.clear()
        _, resources = self.make_resource_pools()
        reasons = [sync.source for sync in RBACSync.objects.changes()]

        rbac_client = MagicMock()
        rbac_client.update_resources.return_value = 'x-y-z'
        service = RegionControllerService(sentinel.listener)
        self.patch(service, '_getRBACClient').return_value = rbac_client
        service.rbacInit = True

        self.assertEquals(reasons, service._rbacSync())
        self.assertThat(rbac_client.update_resources,
                        MockCalledOnceWith('resource-pool', updates=resources))
        self.assertFalse(RBACSync.objects.exists())
        last_sync = RBACLastSync.objects.get()
        self.assertEqual(last_sync.resource_type, 'resource-pool')
        self.assertEqual(last_sync.sync_id, 'x-y-z')
Esempio n. 5
0
    def test__rbacSync_returns_None_when_nothing_to_do(self):
        RBACSync.objects.clear('resource-pool')

        service = RegionControllerService(sentinel.listener)
        service.rbacInit = True
        self.assertIsNone(service._rbacSync())