def setUp(self): prefix = str(uuid.uuid4())[:8] cf_defs = CassandraProvisionerStore.get_column_families(prefix=prefix) ks = cassandra.get_keyspace(cf_defs) self.cassandra_mgr = CassandraSchemaManager(ks) yield self.cassandra_mgr.create() host, port = cassandra.get_host_port() username, password = cassandra.get_credentials() self.store = CassandraProvisionerStore(host, port, username, password, keyspace=ks.name, prefix=prefix) self.store.connect()
class CassandraProvisionerStoreTests(BaseProvisionerStoreTests): """Runs same tests as BaseProvisionerStoreTests but cassandra backend """ @cassandra_test @defer.inlineCallbacks def setUp(self): prefix = str(uuid.uuid4())[:8] cf_defs = CassandraProvisionerStore.get_column_families(prefix=prefix) ks = cassandra.get_keyspace(cf_defs) self.cassandra_mgr = CassandraSchemaManager(ks) yield self.cassandra_mgr.create() host, port = cassandra.get_host_port() username, password = cassandra.get_credentials() self.store = CassandraProvisionerStore(host, port, username, password, keyspace=ks.name, prefix=prefix) self.store.connect() @defer.inlineCallbacks def tearDown(self): yield self.cassandra_mgr.teardown() self.cassandra_mgr.disconnect() self.store.disconnect() @defer.inlineCallbacks def test_paging(self): requested = yield self.put_many_nodes(3, states.REQUESTED) pending = yield self.put_many_nodes(140, states.REQUESTED, states.PENDING) running = yield self.put_many_nodes(160, states.REQUESTED, states.PENDING, states.RUNNING) terminated = yield self.put_many_nodes(120, states.REQUESTED, states.PENDING, states.RUNNING, states.TERMINATING, states.TERMINATED) failed = yield self.put_many_nodes(100, states.REQUESTED, states.FAILED) nodes = yield self.store.get_nodes(state=states.TERMINATED) self.assertEqual(len(nodes), 120) self.assertNodesInSet(nodes, terminated) nodes = yield self.store.get_nodes() self.assertEqual(len(nodes), 523) self.assertNodesInSet(nodes, requested, pending, running, terminated, failed) nodes = yield self.store.get_nodes(state=states.FAILED) self.assertEqual(len(nodes), 100) self.assertNodesInSet(nodes, failed) nodes = yield self.store.get_nodes(min_state=states.REQUESTED) self.assertEqual(len(nodes), 523) self.assertNodesInSet(nodes, requested, pending, running, terminated, failed) nodes = yield self.store.get_nodes(min_state=states.PENDING, max_state=states.RUNNING) self.assertEqual(len(nodes), 300) self.assertNodesInSet(nodes, pending, running) nodes = yield self.store.get_nodes(states.TERMINATING) self.assertEqual(len(nodes), 0) nodes = yield self.store.get_nodes(max_state=states.RUNNING) self.assertEqual(len(nodes), 303) self.assertNodesInSet(nodes, requested, pending, running)