Beispiel #1
0
    def test_node_migrate_between_clusters(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)
        cluster2 = shared.create_cluster(self.ctx, self.profile)

        node = shared.create_node(self.ctx, cluster1, self.profile)
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
        self.assertEqual(1, len(nodes))
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id)
        self.assertEqual(0, len(nodes))
        # Refresh cluster1 and cluster2
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(2, cluster1.next_index)
        self.assertEqual(1, cluster2.next_index)

        timestamp = tu.utcnow()

        node_new = db_api.node_migrate(self.ctx, node.id, cluster2.id,
                                       timestamp)
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(timestamp, node_new.updated_at)
        self.assertEqual(cluster2.id, node_new.cluster_id)
        self.assertIsNone(node_new.role)
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
        self.assertEqual(0, len(nodes))
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id)
        self.assertEqual(1, len(nodes))
        self.assertEqual(2, cluster1.next_index)
        self.assertEqual(2, cluster2.next_index)

        # Migrate it back!
        timestamp = tu.utcnow()

        node_new = db_api.node_migrate(self.ctx, node.id, cluster1.id,
                                       timestamp, 'FAKE-ROLE')
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(timestamp, node_new.updated_at)
        self.assertEqual(cluster1.id, node_new.cluster_id)
        self.assertEqual('FAKE-ROLE', node_new.role)
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
        self.assertEqual(1, len(nodes))
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id)
        self.assertEqual(0, len(nodes))
        self.assertEqual(3, cluster1.next_index)
        self.assertEqual(2, cluster2.next_index)
Beispiel #2
0
    def test_node_migrate_between_clusters(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)
        cluster2 = shared.create_cluster(self.ctx, self.profile)

        node = shared.create_node(self.ctx, cluster1, self.profile)
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
        self.assertEqual(1, len(nodes))
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id)
        self.assertEqual(0, len(nodes))
        # Refresh cluster1 and cluster2
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(2, cluster1.next_index)
        self.assertEqual(1, cluster2.next_index)

        timestamp = tu.utcnow(True)

        node_new = db_api.node_migrate(self.ctx, node.id, cluster2.id,
                                       timestamp)
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(timestamp, node_new.updated_at)
        self.assertEqual(cluster2.id, node_new.cluster_id)
        self.assertIsNone(node_new.role)
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
        self.assertEqual(0, len(nodes))
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id)
        self.assertEqual(1, len(nodes))
        self.assertEqual(2, cluster1.next_index)
        self.assertEqual(2, cluster2.next_index)

        # Migrate it back!
        timestamp = tu.utcnow(True)

        node_new = db_api.node_migrate(self.ctx, node.id, cluster1.id,
                                       timestamp, 'FAKE-ROLE')
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(timestamp, node_new.updated_at)
        self.assertEqual(cluster1.id, node_new.cluster_id)
        self.assertEqual('FAKE-ROLE', node_new.role)
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
        self.assertEqual(1, len(nodes))
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id)
        self.assertEqual(0, len(nodes))
        self.assertEqual(3, cluster1.next_index)
        self.assertEqual(2, cluster2.next_index)
Beispiel #3
0
    def test_node_migrate_to_none(self):
        node = shared.create_node(self.ctx, self.cluster, self.profile)
        timestamp = datetime.datetime.utcnow()

        node_new = db_api.node_migrate(self.ctx, node.id, None, timestamp)
        cluster = db_api.cluster_get(self.ctx, self.cluster.id)
        self.assertEqual(timestamp, node_new.updated_time)
        self.assertIsNone(node_new.cluster_id)
        self.assertEqual(0, cluster.size)
Beispiel #4
0
    def test_node_migrate_to_none(self):
        node = shared.create_node(self.ctx, self.cluster, self.profile)
        timestamp = tu.utcnow(True)

        node_new = db_api.node_migrate(self.ctx, node.id, None, timestamp)
        self.assertEqual(timestamp, node_new.updated_at)
        self.assertEqual('', node_new.cluster_id)
        nodes = db_api.node_get_all_by_cluster(self.ctx, self.cluster.id)
        self.assertEqual(0, len(nodes))
Beispiel #5
0
    def test_node_migrate_to_none(self):
        node = shared.create_node(self.ctx, self.cluster, self.profile)
        timestamp = tu.utcnow()

        node_new = db_api.node_migrate(self.ctx, node.id, None, timestamp)
        self.assertEqual(timestamp, node_new.updated_at)
        self.assertEqual('', node_new.cluster_id)
        nodes = db_api.node_get_all_by_cluster(self.ctx, self.cluster.id)
        self.assertEqual(0, len(nodes))
Beispiel #6
0
    def test_node_migrate_between_clusters(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)
        cluster2 = shared.create_cluster(self.ctx, self.profile)

        node = shared.create_node(self.ctx, cluster1, self.profile)
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
        self.assertEqual(1, len(nodes))
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id)
        self.assertEqual(0, len(nodes))
        self.assertEqual(2, cluster1.next_index)
        self.assertEqual(1, cluster2.next_index)

        timestamp = tu.utcnow()

        node_new = db_api.node_migrate(self.ctx, node.id, cluster2.id,
                                       timestamp)
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(timestamp, node_new.updated_time)
        self.assertEqual(cluster2.id, node_new.cluster_id)
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
        self.assertEqual(0, len(nodes))
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id)
        self.assertEqual(1, len(nodes))
        self.assertEqual(2, cluster1.next_index)
        self.assertEqual(2, cluster2.next_index)

        # Migrate it back!
        timestamp = tu.utcnow()

        node_new = db_api.node_migrate(self.ctx, node.id, cluster1.id,
                                       timestamp)
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(timestamp, node_new.updated_time)
        self.assertEqual(cluster1.id, node_new.cluster_id)
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster1.id)
        self.assertEqual(1, len(nodes))
        nodes = db_api.node_get_all_by_cluster(self.ctx, cluster2.id)
        self.assertEqual(0, len(nodes))
        self.assertEqual(3, cluster1.next_index)
        self.assertEqual(2, cluster2.next_index)
Beispiel #7
0
    def test_node_migrate_from_none(self):
        node_orphan = shared.create_node(self.ctx, None, self.profile)
        timestamp = datetime.datetime.utcnow()

        node = db_api.node_migrate(self.ctx, node_orphan.id, self.cluster.id,
                                   timestamp)
        cluster = db_api.cluster_get(self.ctx, self.cluster.id)
        self.assertEqual(timestamp, node.updated_time)
        self.assertEqual(self.cluster.id, node.cluster_id)
        self.assertEqual(2, cluster.next_index)
        self.assertEqual(1, cluster.size)
Beispiel #8
0
    def test_node_migrate_from_none(self):
        node_orphan = shared.create_node(self.ctx, None, self.profile)
        timestamp = tu.utcnow()

        node = db_api.node_migrate(self.ctx, node_orphan.id, self.cluster.id,
                                   timestamp)
        cluster = db_api.cluster_get(self.ctx, self.cluster.id)
        self.assertEqual(timestamp, node.updated_time)
        self.assertEqual(self.cluster.id, node.cluster_id)
        self.assertEqual(2, cluster.next_index)
        nodes = db_api.node_get_all_by_cluster(self.ctx, self.cluster.id)
        self.assertEqual(1, len(nodes))
Beispiel #9
0
    def test_node_migrate_from_none(self):
        node_orphan = shared.create_node(self.ctx, None, self.profile)
        timestamp = tu.utcnow()

        node = db_api.node_migrate(self.ctx, node_orphan.id, self.cluster.id,
                                   timestamp, 'NEW-ROLE')
        cluster = db_api.cluster_get(self.ctx, self.cluster.id)
        self.assertEqual(timestamp, node.updated_at)
        self.assertEqual(self.cluster.id, node.cluster_id)
        self.assertEqual(2, cluster.next_index)
        nodes = db_api.node_get_all_by_cluster(self.ctx, self.cluster.id)
        self.assertEqual(1, len(nodes))
        self.assertEqual('NEW-ROLE', nodes[0].role)
Beispiel #10
0
    def test_node_migrate_between_clusters(self):
        cluster1 = shared.create_cluster(self.ctx, self.profile)
        cluster2 = shared.create_cluster(self.ctx, self.profile)

        node = shared.create_node(self.ctx, cluster1, self.profile)

        self.assertEqual(1, cluster1.size)
        self.assertEqual(0, cluster2.size)
        self.assertEqual(2, cluster1.next_index)
        self.assertEqual(1, cluster2.next_index)

        timestamp = datetime.datetime.utcnow()

        node_new = db_api.node_migrate(self.ctx, node.id, cluster2.id,
                                       timestamp)
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(timestamp, node_new.updated_time)
        self.assertEqual(cluster2.id, node_new.cluster_id)
        self.assertEqual(0, cluster1.size)
        self.assertEqual(1, cluster2.size)
        self.assertEqual(2, cluster1.next_index)
        self.assertEqual(2, cluster2.next_index)

        # Migrate it back!
        timestamp = datetime.datetime.utcnow()

        node_new = db_api.node_migrate(self.ctx, node.id, cluster1.id,
                                       timestamp)
        cluster1 = db_api.cluster_get(self.ctx, cluster1.id)
        cluster2 = db_api.cluster_get(self.ctx, cluster2.id)
        self.assertEqual(timestamp, node_new.updated_time)
        self.assertEqual(cluster1.id, node_new.cluster_id)
        self.assertEqual(1, cluster1.size)
        self.assertEqual(0, cluster2.size)
        self.assertEqual(3, cluster1.next_index)
        self.assertEqual(2, cluster2.next_index)