class TestRados(object): def setUp(self): self.rados = Rados(conffile='') self.rados.conf_parse_env('FOO_DOES_NOT_EXIST_BLAHBLAH') self.rados.conf_parse_env() self.rados.connect() # Assume any pre-existing pools are the cluster's defaults self.default_pools = self.rados.list_pools() def tearDown(self): self.rados.shutdown() def test_create(self): self.rados.create_pool('foo') self.rados.delete_pool('foo') def test_create_auid(self): self.rados.create_pool('foo', 100) assert self.rados.pool_exists('foo') self.rados.delete_pool('foo') def test_eexist(self): self.rados.create_pool('foo') assert_raises(ObjectExists, self.rados.create_pool, 'foo') self.rados.delete_pool('foo') def list_non_default_pools(self): pools = self.rados.list_pools() for p in self.default_pools: pools.remove(p) return set(pools) def test_list_pools(self): eq(set(), self.list_non_default_pools()) self.rados.create_pool('foo') eq(set(['foo']), self.list_non_default_pools()) self.rados.create_pool('bar') eq(set(['foo', 'bar']), self.list_non_default_pools()) self.rados.create_pool('baz') eq(set(['foo', 'bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('foo') eq(set(['bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('baz') eq(set(['bar']), self.list_non_default_pools()) self.rados.delete_pool('bar') eq(set(), self.list_non_default_pools()) self.rados.create_pool('a' * 500) eq(set(['a' * 500]), self.list_non_default_pools()) self.rados.delete_pool('a' * 500) def test_get_fsid(self): fsid = self.rados.get_fsid() eq(len(fsid), 36)
class TestRados(object): def setUp(self): self.rados = Rados(conffile='') self.rados.conf_parse_env('FOO_DOES_NOT_EXIST_BLAHBLAH') self.rados.conf_parse_env() self.rados.connect() # Assume any pre-existing pools are the cluster's defaults self.default_pools = self.rados.list_pools() def tearDown(self): self.rados.shutdown() def test_ping_monitor(self): assert_raises(ObjectNotFound, self.rados.ping_monitor, 'not_exists_monitor') cmd = {'prefix': 'mon dump', 'format': 'json'} ret, buf, out = self.rados.mon_command(json.dumps(cmd), b'') for mon in json.loads(buf.decode('utf8'))['mons']: while True: output = self.rados.ping_monitor(mon['name']) if output is None: continue buf = json.loads(output) if buf.get('health'): break def test_create(self): self.rados.create_pool('foo') self.rados.delete_pool('foo') def test_create_utf8(self): if _python2: # Use encoded bytestring poolname = b"\351\273\204" else: poolname = "\u9ec4" self.rados.create_pool(poolname) assert self.rados.pool_exists(u"\u9ec4") self.rados.delete_pool(poolname) def test_pool_lookup_utf8(self): if _python2: poolname = u'\u9ec4' else: poolname = '\u9ec4' self.rados.create_pool(poolname) try: poolid = self.rados.pool_lookup(poolname) eq(poolname, self.rados.pool_reverse_lookup(poolid)) finally: self.rados.delete_pool(poolname) def test_create_auid(self): self.rados.create_pool('foo', 100) assert self.rados.pool_exists('foo') self.rados.delete_pool('foo') def test_eexist(self): self.rados.create_pool('foo') assert_raises(ObjectExists, self.rados.create_pool, 'foo') self.rados.delete_pool('foo') def list_non_default_pools(self): pools = self.rados.list_pools() for p in self.default_pools: pools.remove(p) return set(pools) def test_list_pools(self): eq(set(), self.list_non_default_pools()) self.rados.create_pool('foo') eq(set(['foo']), self.list_non_default_pools()) self.rados.create_pool('bar') eq(set(['foo', 'bar']), self.list_non_default_pools()) self.rados.create_pool('baz') eq(set(['foo', 'bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('foo') eq(set(['bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('baz') eq(set(['bar']), self.list_non_default_pools()) self.rados.delete_pool('bar') eq(set(), self.list_non_default_pools()) self.rados.create_pool('a' * 500) eq(set(['a' * 500]), self.list_non_default_pools()) self.rados.delete_pool('a' * 500) def test_get_pool_base_tier(self): self.rados.create_pool('foo') try: self.rados.create_pool('foo-cache') try: pool_id = self.rados.pool_lookup('foo') tier_pool_id = self.rados.pool_lookup('foo-cache') cmd = { "prefix": "osd tier add", "pool": "foo", "tierpool": "foo-cache", "force_nonempty": "" } ret, buf, errs = self.rados.mon_command(json.dumps(cmd), b'', timeout=30) eq(ret, 0) try: cmd = { "prefix": "osd tier cache-mode", "pool": "foo-cache", "tierpool": "foo-cache", "mode": "readonly", "sure": "--yes-i-really-mean-it" } ret, buf, errs = self.rados.mon_command(json.dumps(cmd), b'', timeout=30) eq(ret, 0) eq(self.rados.wait_for_latest_osdmap(), 0) eq(pool_id, self.rados.get_pool_base_tier(pool_id)) eq(pool_id, self.rados.get_pool_base_tier(tier_pool_id)) finally: cmd = { "prefix": "osd tier remove", "pool": "foo", "tierpool": "foo-cache" } ret, buf, errs = self.rados.mon_command(json.dumps(cmd), b'', timeout=30) eq(ret, 0) finally: self.rados.delete_pool('foo-cache') finally: self.rados.delete_pool('foo') def test_get_fsid(self): fsid = self.rados.get_fsid() eq(len(fsid), 36) def test_blacklist_add(self): self.rados.blacklist_add("1.2.3.4/123", 1) def test_get_cluster_stats(self): stats = self.rados.get_cluster_stats() assert stats['kb'] > 0 assert stats['kb_avail'] > 0 assert stats['kb_used'] > 0 assert stats['num_objects'] >= 0 def test_monitor_log(self): lock = threading.Condition() def cb(arg, line, who, sec, nsec, seq, level, msg): # NOTE(sileht): the old pyrados API was received the pointer as int # instead of the value of arg eq(arg, "arg") with lock: lock.notify() return 0 # NOTE(sileht): force don't save the monitor into local var # to ensure all references are correctly tracked into the lib MonitorLog(self.rados, "debug", cb, "arg") with lock: lock.wait() MonitorLog(self.rados, "debug", None, None) eq(None, self.rados.monitor_callback)
class TestRados(object): def setUp(self): self.rados = Rados(conffile='') self.rados.conf_parse_env('FOO_DOES_NOT_EXIST_BLAHBLAH') self.rados.conf_parse_env() self.rados.connect() # Assume any pre-existing pools are the cluster's defaults self.default_pools = self.rados.list_pools() def tearDown(self): self.rados.shutdown() def test_ping_monitor(self): assert_raises(ObjectNotFound, self.rados.ping_monitor, 'not_exists_monitor') cmd = {'prefix': 'mon dump', 'format':'json'} ret, buf, out = self.rados.mon_command(json.dumps(cmd), b'') for mon in json.loads(buf.decode('utf8'))['mons']: while True: buf = json.loads(self.rados.ping_monitor(mon['name'])) if buf.get('health'): break def test_create(self): self.rados.create_pool('foo') self.rados.delete_pool('foo') def test_create_utf8(self): if _python2: # Use encoded bytestring poolname = b"\351\273\204" else: poolname = "\u9ec4" self.rados.create_pool(poolname) assert self.rados.pool_exists(u"\u9ec4") self.rados.delete_pool(poolname) def test_pool_lookup_utf8(self): if _python2: poolname = u'\u9ec4' else: poolname = '\u9ec4' self.rados.create_pool(poolname) try: poolid = self.rados.pool_lookup(poolname) eq(poolname, self.rados.pool_reverse_lookup(poolid)) finally: self.rados.delete_pool(poolname) def test_create_auid(self): self.rados.create_pool('foo', 100) assert self.rados.pool_exists('foo') self.rados.delete_pool('foo') def test_eexist(self): self.rados.create_pool('foo') assert_raises(ObjectExists, self.rados.create_pool, 'foo') self.rados.delete_pool('foo') def list_non_default_pools(self): pools = self.rados.list_pools() for p in self.default_pools: pools.remove(p) return set(pools) def test_list_pools(self): eq(set(), self.list_non_default_pools()) self.rados.create_pool('foo') eq(set(['foo']), self.list_non_default_pools()) self.rados.create_pool('bar') eq(set(['foo', 'bar']), self.list_non_default_pools()) self.rados.create_pool('baz') eq(set(['foo', 'bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('foo') eq(set(['bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('baz') eq(set(['bar']), self.list_non_default_pools()) self.rados.delete_pool('bar') eq(set(), self.list_non_default_pools()) self.rados.create_pool('a' * 500) eq(set(['a' * 500]), self.list_non_default_pools()) self.rados.delete_pool('a' * 500) def test_get_pool_base_tier(self): self.rados.create_pool('foo') try: self.rados.create_pool('foo-cache') try: pool_id = self.rados.pool_lookup('foo') tier_pool_id = self.rados.pool_lookup('foo-cache') cmd = {"prefix":"osd tier add", "pool":"foo", "tierpool":"foo-cache", "force_nonempty":""} ret, buf, errs = self.rados.mon_command(json.dumps(cmd), b'', timeout=30) eq(ret, 0) try: cmd = {"prefix":"osd tier cache-mode", "pool":"foo-cache", "tierpool":"foo-cache", "mode":"readonly", "sure":"--yes-i-really-mean-it"} ret, buf, errs = self.rados.mon_command(json.dumps(cmd), b'', timeout=30) eq(ret, 0) eq(self.rados.wait_for_latest_osdmap(), 0) eq(pool_id, self.rados.get_pool_base_tier(pool_id)) eq(pool_id, self.rados.get_pool_base_tier(tier_pool_id)) finally: cmd = {"prefix":"osd tier remove", "pool":"foo", "tierpool":"foo-cache"} ret, buf, errs = self.rados.mon_command(json.dumps(cmd), b'', timeout=30) eq(ret, 0) finally: self.rados.delete_pool('foo-cache') finally: self.rados.delete_pool('foo') def test_get_fsid(self): fsid = self.rados.get_fsid() eq(len(fsid), 36) def test_blacklist_add(self): self.rados.blacklist_add("1.2.3.4/123", 1) def test_get_cluster_stats(self): stats = self.rados.get_cluster_stats() assert stats['kb'] > 0 assert stats['kb_avail'] > 0 assert stats['kb_used'] > 0 assert stats['num_objects'] >= 0 def test_monitor_log(self): lock = threading.Condition() def cb(arg, line, who, sec, nsec, seq, level, msg): # NOTE(sileht): the old pyrados API was received the pointer as int # instead of the value of arg eq(arg, "arg") with lock: lock.notify() return 0 # NOTE(sileht): force don't save the monitor into local var # to ensure all references are correctly tracked into the lib MonitorLog(self.rados, "debug", cb, "arg") with lock: lock.wait() MonitorLog(self.rados, "debug", None, None) eq(None, self.rados.monitor_callback)
class TestRados(object): def setUp(self): self.rados = Rados(conffile='') self.rados.conf_parse_env('FOO_DOES_NOT_EXIST_BLAHBLAH') self.rados.conf_parse_env() self.rados.connect() # Assume any pre-existing pools are the cluster's defaults self.default_pools = self.rados.list_pools() def tearDown(self): self.rados.shutdown() def test_create(self): self.rados.create_pool('foo') self.rados.delete_pool('foo') def test_create_auid(self): self.rados.create_pool('foo', 100) assert self.rados.pool_exists('foo') self.rados.delete_pool('foo') def test_eexist(self): self.rados.create_pool('foo') assert_raises(ObjectExists, self.rados.create_pool, 'foo') self.rados.delete_pool('foo') def list_non_default_pools(self): pools = self.rados.list_pools() for p in self.default_pools: pools.remove(p) return set(pools) def test_list_pools(self): eq(set(), self.list_non_default_pools()) self.rados.create_pool('foo') eq(set(['foo']), self.list_non_default_pools()) self.rados.create_pool('bar') eq(set(['foo', 'bar']), self.list_non_default_pools()) self.rados.create_pool('baz') eq(set(['foo', 'bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('foo') eq(set(['bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('baz') eq(set(['bar']), self.list_non_default_pools()) self.rados.delete_pool('bar') eq(set(), self.list_non_default_pools()) self.rados.create_pool('a' * 500) eq(set(['a' * 500]), self.list_non_default_pools()) self.rados.delete_pool('a' * 500) def test_get_pool_base_tier(self): self.rados.create_pool('foo') try: self.rados.create_pool('foo-cache') try: pool_id = self.rados.pool_lookup('foo') tier_pool_id = self.rados.pool_lookup('foo-cache') cmd = { "prefix": "osd tier add", "pool": "foo", "tierpool": "foo-cache", "force_nonempty": "" } ret, buf, errs = self.rados.mon_command(json.dumps(cmd), '', timeout=30) eq(ret, 0) try: cmd = { "prefix": "osd tier cache-mode", "pool": "foo-cache", "tierpool": "foo-cache", "mode": "readonly" } ret, buf, errs = self.rados.mon_command(json.dumps(cmd), '', timeout=30) eq(ret, 0) eq(self.rados.wait_for_latest_osdmap(), 0) eq(pool_id, self.rados.get_pool_base_tier(pool_id)) eq(pool_id, self.rados.get_pool_base_tier(tier_pool_id)) finally: cmd = { "prefix": "osd tier remove", "pool": "foo", "tierpool": "foo-cache" } ret, buf, errs = self.rados.mon_command(json.dumps(cmd), '', timeout=30) eq(ret, 0) finally: self.rados.delete_pool('foo-cache') finally: self.rados.delete_pool('foo') def test_get_fsid(self): fsid = self.rados.get_fsid() eq(len(fsid), 36)
class TestRados(object): def setUp(self): self.rados = Rados(conffile='') self.rados.conf_parse_env('FOO_DOES_NOT_EXIST_BLAHBLAH') self.rados.conf_parse_env() self.rados.connect() # Assume any pre-existing pools are the cluster's defaults self.default_pools = self.rados.list_pools() def tearDown(self): self.rados.shutdown() def test_create(self): self.rados.create_pool('foo') self.rados.delete_pool('foo') def test_create_auid(self): self.rados.create_pool('foo', 100) assert self.rados.pool_exists('foo') self.rados.delete_pool('foo') def test_eexist(self): self.rados.create_pool('foo') assert_raises(ObjectExists, self.rados.create_pool, 'foo') self.rados.delete_pool('foo') def list_non_default_pools(self): pools = self.rados.list_pools() for p in self.default_pools: pools.remove(p) return set(pools) def test_list_pools(self): eq(set(), self.list_non_default_pools()) self.rados.create_pool('foo') eq(set(['foo']), self.list_non_default_pools()) self.rados.create_pool('bar') eq(set(['foo', 'bar']), self.list_non_default_pools()) self.rados.create_pool('baz') eq(set(['foo', 'bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('foo') eq(set(['bar', 'baz']), self.list_non_default_pools()) self.rados.delete_pool('baz') eq(set(['bar']), self.list_non_default_pools()) self.rados.delete_pool('bar') eq(set(), self.list_non_default_pools()) self.rados.create_pool('a' * 500) eq(set(['a' * 500]), self.list_non_default_pools()) self.rados.delete_pool('a' * 500) def test_get_pool_base_tier(self): self.rados.create_pool('foo') try: self.rados.create_pool('foo-cache') try: pool_id = self.rados.pool_lookup('foo') tier_pool_id = self.rados.pool_lookup('foo-cache') cmd = {"prefix":"osd tier add", "pool":"foo", "tierpool":"foo-cache", "force_nonempty":""} ret, buf, errs = self.rados.mon_command(json.dumps(cmd), '', timeout=30) eq(ret, 0) try: cmd = {"prefix":"osd tier cache-mode", "pool":"foo-cache", "tierpool":"foo-cache", "mode":"readonly"} ret, buf, errs = self.rados.mon_command(json.dumps(cmd), '', timeout=30) eq(ret, 0) eq(self.rados.wait_for_latest_osdmap(), 0) eq(pool_id, self.rados.get_pool_base_tier(pool_id)) eq(pool_id, self.rados.get_pool_base_tier(tier_pool_id)) finally: cmd = {"prefix":"osd tier remove", "pool":"foo", "tierpool":"foo-cache"} ret, buf, errs = self.rados.mon_command(json.dumps(cmd), '', timeout=30) eq(ret, 0) finally: self.rados.delete_pool('foo-cache') finally: self.rados.delete_pool('foo') def test_get_fsid(self): fsid = self.rados.get_fsid() eq(len(fsid), 36)