diff --git a/src/actions.yaml b/src/actions.yaml index 972de6c..dccfc81 100644 --- a/src/actions.yaml +++ b/src/actions.yaml @@ -1,15 +1,25 @@ demote: description: | - Demote all primary images within all pools to non-primary. + Demote all primary images within given pools to non-primary. params: force: type: boolean + pools: + type: string + description: | + Comma-separated list of pools to demote. If this is not set, all the + pools will be demoted. promote: description: | - Promote all non-primary images within all pools to primary. + Promote all non-primary images within given pools to primary. params: force: type: boolean + pools: + type: string + description: | + Comma-separated list of pools to promote. If this is not set, all the + pools will be promoted. refresh-pools: description: | \ @@ -19,13 +29,19 @@ refresh-pools: resync-pools: description: | \ - USE WITH CAUTION - Force image resync for all images in pools on local - Ceph endpoint. + USE WITH CAUTION - Force image resync for all images in the given + pools on local Ceph endpoint. params: i-really-mean-it: type: boolean description: | This must be set to true to perform the action + pools: + type: string + description: | + Comma-separated list of pools to resync from the local Ceph endpoint. + If this is not set, all the pools from the local Ceph endpoint will + be resynced. required: - i-really-mean-it status: @@ -41,3 +57,8 @@ status: - plain - json - xml + pools: + type: string + description: | + Comma-separated list of pools to include in the status. If this is + not set, all the pools will be included. diff --git a/src/actions/actions.py b/src/actions/actions.py index caa4888..92465f7 100755 --- a/src/actions/actions.py +++ b/src/actions/actions.py @@ -40,12 +40,22 @@ ch_core.hookenv._run_atstart() charms_openstack.bus.discover() +def get_pools(): + """Get the list of pools given as parameter to perform the actions on.""" + pools = ch_core.hookenv.action_get('pools') + if pools: + return [p.strip() for p in pools.split(',')] + return None + + def rbd_mirror_action(args): """Perform RBD command on pools in local Ceph endpoint.""" action_name = os.path.basename(args[0]) with charms_openstack.charm.provide_charm_instance() as charm: ceph_local = reactive.endpoint_from_name('ceph-local') - pools = charm.eligible_pools(ceph_local.pools) + pools = get_pools() + if not pools: + pools = charm.eligible_pools(ceph_local.pools) result = {} cmd = ['rbd', '--id', charm.ceph_id, 'mirror', 'pool', action_name] if ch_core.hookenv.action_get('force'): @@ -103,7 +113,9 @@ def resync_pools(args): return with charms_openstack.charm.provide_charm_instance() as charm: ceph_local = reactive.endpoint_from_name('ceph-local') - pools = charm.eligible_pools(ceph_local.pools) + pools = get_pools() + if not pools: + pools = charm.eligible_pools(ceph_local.pools) result = collections.defaultdict(dict) for pool in pools: # list images in pool @@ -112,6 +124,12 @@ def resync_pools(args): '-p', pool, 'ls'], universal_newlines=True) images = json.loads(output) for image in images: + output = subprocess.check_output( + ['rbd', '--id', charm.ceph_id, '--format', 'json', 'info', + '{}/{}'.format(pool, image)], universal_newlines=True) + image_info = json.loads(output) + if image_info['mirroring']['state'] == 'disabled': + continue output = subprocess.check_output( ['rbd', '--id', charm.ceph_id, 'mirror', 'image', 'resync', '{}/{}'.format(pool, image)], universal_newlines=True) diff --git a/src/tests/bundles/bionic-train-image-mirroring.yaml b/src/tests/bundles/bionic-train-image-mirroring.yaml new file mode 100644 index 0000000..80b210c --- /dev/null +++ b/src/tests/bundles/bionic-train-image-mirroring.yaml @@ -0,0 +1,120 @@ +series: bionic +applications: + mysql: + charm: cs:~openstack-charmers-next/percona-cluster + num_units: 1 + options: + source: cloud:bionic-train + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: cloud:bionic-train + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + options: + source: cloud:bionic-train + cinder: + charm: cs:~openstack-charmers-next/cinder + num_units: 1 + options: + block-device: None + glance-api-version: 2 + openstack-origin: cloud:bionic-train + cinder-ceph: + charm: cs:~openstack-charmers-next/cinder-ceph + num_units: 0 + options: + rbd-mirroring-mode: image + glance: + charm: cs:~openstack-charmers-next/glance + num_units: 1 + options: + openstack-origin: cloud:bionic-train + nova-compute: + charm: cs:~openstack-charmers-next/nova-compute + num_units: 1 + options: + openstack-origin: cloud:bionic-train + ceph-mon: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: cloud:bionic-train + ceph-osd: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: cloud:bionic-train + #bluestore: False + #use-direct-io: False + storage: + osd-devices: '10G' + ceph-rbd-mirror: + series: bionic + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: cloud:bionic-train + ceph-mon-b: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: cloud:bionic-train + ceph-osd-b: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: cloud:bionic-train + #bluestore: False + #use-direct-io: False + storage: + osd-devices: '10G' + ceph-rbd-mirror-b: + series: bionic + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: cloud:bionic-train +relations: +- - mysql + - keystone +- - mysql + - cinder +- - mysql + - glance +- - rabbitmq-server + - cinder +- - keystone + - cinder +- - keystone + - glance +- - cinder + - cinder-ceph +- - cinder-ceph:ceph + - ceph-mon:client +- - nova-compute:ceph-access + - cinder-ceph:ceph-access +- - nova-compute:amqp + - rabbitmq-server:amqp +- - glance:image-service + - nova-compute:image-service +- - glance + - ceph-mon +- - ceph-mon:osd + - ceph-osd:mon +- - ceph-mon + - ceph-rbd-mirror:ceph-local +- - ceph-mon + - ceph-rbd-mirror-b:ceph-remote +- - ceph-mon-b:osd + - ceph-osd-b:mon +- - ceph-mon-b + - ceph-rbd-mirror-b:ceph-local +- - ceph-mon-b + - ceph-rbd-mirror:ceph-remote +- - cinder-ceph:ceph-replication-device + - ceph-mon-b:client diff --git a/src/tests/bundles/bionic-ussuri-image-mirroring.yaml b/src/tests/bundles/bionic-ussuri-image-mirroring.yaml new file mode 100644 index 0000000..3e95360 --- /dev/null +++ b/src/tests/bundles/bionic-ussuri-image-mirroring.yaml @@ -0,0 +1,120 @@ +series: bionic +applications: + mysql: + charm: cs:~openstack-charmers-next/percona-cluster + num_units: 1 + options: + source: cloud:bionic-ussuri + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: cloud:bionic-ussuri + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + options: + source: cloud:bionic-ussuri + cinder: + charm: cs:~openstack-charmers-next/cinder + num_units: 1 + options: + block-device: None + glance-api-version: 2 + openstack-origin: cloud:bionic-ussuri + cinder-ceph: + charm: cs:~openstack-charmers-next/cinder-ceph + num_units: 0 + options: + rbd-mirroring-mode: image + glance: + charm: cs:~openstack-charmers-next/glance + num_units: 1 + options: + openstack-origin: cloud:bionic-ussuri + nova-compute: + charm: cs:~openstack-charmers-next/nova-compute + num_units: 1 + options: + openstack-origin: cloud:bionic-ussuri + ceph-mon: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: cloud:bionic-ussuri + ceph-osd: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: cloud:bionic-ussuri + #bluestore: False + #use-direct-io: False + storage: + osd-devices: '10G' + ceph-rbd-mirror: + series: bionic + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: cloud:bionic-ussuri + ceph-mon-b: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: cloud:bionic-ussuri + ceph-osd-b: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: cloud:bionic-ussuri + #bluestore: False + #use-direct-io: False + storage: + osd-devices: '10G' + ceph-rbd-mirror-b: + series: bionic + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: cloud:bionic-ussuri +relations: +- - mysql + - keystone +- - mysql + - cinder +- - mysql + - glance +- - rabbitmq-server + - cinder +- - keystone + - cinder +- - keystone + - glance +- - cinder + - cinder-ceph +- - cinder-ceph:ceph + - ceph-mon:client +- - nova-compute:ceph-access + - cinder-ceph:ceph-access +- - nova-compute:amqp + - rabbitmq-server:amqp +- - glance:image-service + - nova-compute:image-service +- - glance + - ceph-mon +- - ceph-mon:osd + - ceph-osd:mon +- - ceph-mon + - ceph-rbd-mirror:ceph-local +- - ceph-mon + - ceph-rbd-mirror-b:ceph-remote +- - ceph-mon-b:osd + - ceph-osd-b:mon +- - ceph-mon-b + - ceph-rbd-mirror-b:ceph-local +- - ceph-mon-b + - ceph-rbd-mirror:ceph-remote +- - cinder-ceph:ceph-replication-device + - ceph-mon-b:client diff --git a/src/tests/bundles/focal-ussuri-image-mirroring.yaml b/src/tests/bundles/focal-ussuri-image-mirroring.yaml new file mode 100644 index 0000000..ea148e3 --- /dev/null +++ b/src/tests/bundles/focal-ussuri-image-mirroring.yaml @@ -0,0 +1,233 @@ +variables: + openstack-origin: &openstack-origin distro + +series: focal + +comment: +- 'machines section to decide order of deployment. database sooner = faster' +machines: + '0': + constraints: mem=3072M + '1': + constraints: mem=3072M + '2': + constraints: mem=3072M + '3': + '4': + '5': + '6': + '7': + '8': + '9': + '10': + '11': + '12': + '13': + '14': + '15': + '16': + '17': + '18': + '19': + '20': + '21': + +applications: + + cinder-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + + keystone-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + + glance-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + + mysql-innodb-cluster: + charm: cs:~openstack-charmers-next/mysql-innodb-cluster + num_units: 3 + options: + source: *openstack-origin + to: + - '0' + - '1' + - '2' + + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '3' + + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + options: + source: *openstack-origin + to: + - '4' + + cinder: + charm: cs:~openstack-charmers-next/cinder + num_units: 1 + options: + block-device: None + glance-api-version: 2 + openstack-origin: *openstack-origin + to: + - '5' + + cinder-ceph: + charm: cs:~openstack-charmers-next/cinder-ceph + num_units: 0 + options: + rbd-mirroring-mode: image + + glance: + charm: cs:~openstack-charmers-next/glance + num_units: 1 + options: + openstack-origin: *openstack-origin + to: + - '6' + + nova-compute: + charm: cs:~openstack-charmers-next/nova-compute + num_units: 1 + to: + - '7' + + ceph-mon: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: *openstack-origin + to: + - '8' + - '9' + - '10' + + ceph-osd: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: *openstack-origin + #bluestore: False + #use-direct-io: False + storage: + osd-devices: '10G' + to: + - '11' + - '12' + - '13' + + ceph-rbd-mirror: + series: focal + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: *openstack-origin + to: + - '14' + + ceph-mon-b: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: *openstack-origin + to: + - '15' + - '16' + - '17' + + ceph-osd-b: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: *openstack-origin + #bluestore: False + #use-direct-io: False + storage: + osd-devices: '10G' + to: + - '18' + - '19' + - '20' + + ceph-rbd-mirror-b: + series: focal + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: *openstack-origin + to: + - '21' + +relations: + + - - 'keystone:shared-db' + - 'keystone-mysql-router:shared-db' + - - 'keystone-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'cinder:shared-db' + - 'cinder-mysql-router:shared-db' + - - 'cinder-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'glance:shared-db' + - 'glance-mysql-router:shared-db' + - - 'glance-mysql-router:db-router' + - 'mysql-innodb-cluster:db-router' + + - - 'rabbitmq-server' + - 'cinder' + + - - 'keystone' + - 'cinder' + + - - 'keystone' + - 'glance' + + - - 'cinder' + - 'cinder-ceph' + + - - 'cinder-ceph:ceph' + - 'ceph-mon:client' + + - - 'cinder-ceph:ceph-replication-device' + - 'ceph-mon-b:client' + + - - 'nova-compute:ceph-access' + - 'cinder-ceph:ceph-access' + + - - 'nova-compute:amqp' + - 'rabbitmq-server:amqp' + + - - 'glance:image-service' + - 'nova-compute:image-service' + + - - 'glance' + - 'ceph-mon' + + - - 'ceph-mon:osd' + - 'ceph-osd:mon' + + - - 'ceph-mon' + - 'ceph-rbd-mirror:ceph-local' + + - - 'ceph-mon' + - 'ceph-rbd-mirror-b:ceph-remote' + + - - 'ceph-mon-b:osd' + - 'ceph-osd-b:mon' + + - - 'ceph-mon-b' + - 'ceph-rbd-mirror-b:ceph-local' + + - - 'ceph-mon-b' + - 'ceph-rbd-mirror:ceph-remote' diff --git a/src/tests/bundles/focal-victoria-image-mirroring.yaml b/src/tests/bundles/focal-victoria-image-mirroring.yaml new file mode 100644 index 0000000..2d8d433 --- /dev/null +++ b/src/tests/bundles/focal-victoria-image-mirroring.yaml @@ -0,0 +1,171 @@ +variables: + openstack-origin: &openstack-origin cloud:focal-victoria + +series: &series focal + +machines: + '0': + constraints: "mem=3072M" + '1': + constraints: "mem=3072M" + '2': + constraints: "mem=3072M" + +applications: + + keystone-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + glance-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + cinder-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + + mysql-innodb-cluster: + charm: cs:~openstack-charmers-next/mysql-innodb-cluster + num_units: 3 + options: + source: *openstack-origin + to: + - '0' + - '1' + - '2' + + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: *openstack-origin + + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + options: + source: *openstack-origin + + cinder: + charm: cs:~openstack-charmers-next/cinder + num_units: 1 + options: + block-device: None + glance-api-version: 2 + openstack-origin: *openstack-origin + + cinder-ceph: + charm: cs:~openstack-charmers-next/cinder-ceph + num_units: 0 + options: + rbd-mirroring-mode: image + + glance: + charm: cs:~openstack-charmers-next/glance + num_units: 1 + options: + openstack-origin: *openstack-origin + + nova-compute: + charm: cs:~openstack-charmers-next/nova-compute + num_units: 1 + options: + openstack-origin: *openstack-origin + + ceph-mon: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: *openstack-origin + + ceph-osd: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: *openstack-origin + bluestore: False + use-direct-io: False + osd-devices: /opt + + ceph-rbd-mirror: + series: *series + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: *openstack-origin + + ceph-mon-b: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: *openstack-origin + + ceph-osd-b: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: *openstack-origin + bluestore: False + use-direct-io: False + osd-devices: /opt + + ceph-rbd-mirror-b: + series: *series + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: *openstack-origin + +relations: + +- - keystone:shared-db + - keystone-mysql-router:shared-db +- - keystone-mysql-router:db-router + - mysql-innodb-cluster:db-router + +- - glance:shared-db + - glance-mysql-router:shared-db +- - glance-mysql-router:db-router + - mysql-innodb-cluster:db-router + +- - cinder:shared-db + - cinder-mysql-router:shared-db +- - cinder-mysql-router:db-router + - mysql-innodb-cluster:db-router + +- - rabbitmq-server + - cinder + +- - keystone + - cinder +- - keystone + - glance + +- - cinder + - cinder-ceph +- - cinder-ceph:ceph + - ceph-mon:client +- - cinder-ceph:ceph-replication-device + - ceph-mon-b:client + +- - nova-compute:ceph-access + - cinder-ceph:ceph-access +- - nova-compute:amqp + - rabbitmq-server:amqp + +- - glance:image-service + - nova-compute:image-service +- - glance + - ceph-mon + +- - ceph-mon:osd + - ceph-osd:mon +- - ceph-mon + - ceph-rbd-mirror:ceph-local +- - ceph-mon + - ceph-rbd-mirror-b:ceph-remote + +- - ceph-mon-b:osd + - ceph-osd-b:mon +- - ceph-mon-b + - ceph-rbd-mirror-b:ceph-local +- - ceph-mon-b + - ceph-rbd-mirror:ceph-remote diff --git a/src/tests/bundles/groovy-victoria-image-mirroring.yaml b/src/tests/bundles/groovy-victoria-image-mirroring.yaml new file mode 100644 index 0000000..90ad5b0 --- /dev/null +++ b/src/tests/bundles/groovy-victoria-image-mirroring.yaml @@ -0,0 +1,171 @@ +variables: + openstack-origin: &openstack-origin distro + +series: &series groovy + +machines: + '0': + constraints: "mem=3072M" + '1': + constraints: "mem=3072M" + '2': + constraints: "mem=3072M" + +applications: + + keystone-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + glance-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + cinder-mysql-router: + charm: cs:~openstack-charmers-next/mysql-router + + mysql-innodb-cluster: + charm: cs:~openstack-charmers-next/mysql-innodb-cluster + num_units: 3 + options: + source: *openstack-origin + to: + - '0' + - '1' + - '2' + + keystone: + charm: cs:~openstack-charmers-next/keystone + num_units: 1 + options: + openstack-origin: *openstack-origin + + rabbitmq-server: + charm: cs:~openstack-charmers-next/rabbitmq-server + num_units: 1 + options: + source: *openstack-origin + + cinder: + charm: cs:~openstack-charmers-next/cinder + num_units: 1 + options: + block-device: None + glance-api-version: 2 + openstack-origin: *openstack-origin + + cinder-ceph: + charm: cs:~openstack-charmers-next/cinder-ceph + num_units: 0 + options: + rbd-mirroring-mode: image + + glance: + charm: cs:~openstack-charmers-next/glance + num_units: 1 + options: + openstack-origin: *openstack-origin + + nova-compute: + charm: cs:~openstack-charmers-next/nova-compute + num_units: 1 + options: + openstack-origin: *openstack-origin + + ceph-mon: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: *openstack-origin + + ceph-osd: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: *openstack-origin + bluestore: False + use-direct-io: False + osd-devices: /opt + + ceph-rbd-mirror: + series: *series + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: *openstack-origin + + ceph-mon-b: + charm: cs:~openstack-charmers-next/ceph-mon + num_units: 3 + options: + expected-osd-count: 3 + source: *openstack-origin + + ceph-osd-b: + charm: cs:~openstack-charmers-next/ceph-osd + num_units: 3 + options: + source: *openstack-origin + bluestore: False + use-direct-io: False + osd-devices: /opt + + ceph-rbd-mirror-b: + series: *series + charm: ../../../ceph-rbd-mirror + num_units: 1 + options: + source: *openstack-origin + +relations: + +- - keystone:shared-db + - keystone-mysql-router:shared-db +- - keystone-mysql-router:db-router + - mysql-innodb-cluster:db-router + +- - glance:shared-db + - glance-mysql-router:shared-db +- - glance-mysql-router:db-router + - mysql-innodb-cluster:db-router + +- - cinder:shared-db + - cinder-mysql-router:shared-db +- - cinder-mysql-router:db-router + - mysql-innodb-cluster:db-router + +- - rabbitmq-server + - cinder + +- - keystone + - cinder +- - keystone + - glance + +- - cinder + - cinder-ceph +- - cinder-ceph:ceph + - ceph-mon:client +- - cinder-ceph:ceph-replication-device + - ceph-mon-b:client + +- - nova-compute:ceph-access + - cinder-ceph:ceph-access +- - nova-compute:amqp + - rabbitmq-server:amqp + +- - glance:image-service + - nova-compute:image-service +- - glance + - ceph-mon + +- - ceph-mon:osd + - ceph-osd:mon +- - ceph-mon + - ceph-rbd-mirror:ceph-local +- - ceph-mon + - ceph-rbd-mirror-b:ceph-remote + +- - ceph-mon-b:osd + - ceph-osd-b:mon +- - ceph-mon-b + - ceph-rbd-mirror-b:ceph-local +- - ceph-mon-b + - ceph-rbd-mirror:ceph-remote diff --git a/src/tests/bundles/groovy-victoria.yaml b/src/tests/bundles/groovy-victoria.yaml index f0eb067..8c1453a 100644 --- a/src/tests/bundles/groovy-victoria.yaml +++ b/src/tests/bundles/groovy-victoria.yaml @@ -48,6 +48,7 @@ applications: options: block-device: None glance-api-version: 2 + openstack-origin: *openstack-origin cinder-ceph: charm: cs:~openstack-charmers-next/cinder-ceph diff --git a/src/tests/tests.yaml b/src/tests/tests.yaml index dad4b24..abbdd2b 100644 --- a/src/tests/tests.yaml +++ b/src/tests/tests.yaml @@ -3,6 +3,7 @@ smoke_bundles: - bionic-train gate_bundles: - bionic-train +- bionic-train-image-mirroring - bionic-stein - bionic-queens comment: | @@ -10,12 +11,17 @@ comment: | the functional tests. dev_bundles: - groovy-victoria +- groovy-victoria-image-mirroring - focal-victoria +- focal-victoria-image-mirroring - bionic-queens-e2e - bionic-queens-e2e-lxd - bionic-rocky - bionic-ussuri +# This is a dev bundle because we hit https://bugs.launchpad.net/charm-ceph-rbd-mirror/+bug/1892201. +- bionic-ussuri-image-mirroring - focal-ussuri +- focal-ussuri-image-mirroring - xenial-queens - xenial-pike configure: diff --git a/unit_tests/test_actions.py b/unit_tests/test_actions.py index 1ec4bcc..d2349bf 100644 --- a/unit_tests/test_actions.py +++ b/unit_tests/test_actions.py @@ -55,6 +55,7 @@ class TestCephRBDMirrorActions(test_utils.PatchHelper): self.endpoint_from_name.assert_called_once_with('ceph-local') self.crm_charm.eligible_pools.assert_called_once_with(endpoint.pools) self.action_get.assert_has_calls([ + mock.call('pools'), mock.call('force'), mock.call('verbose'), mock.call('format'), @@ -76,7 +77,7 @@ class TestCephRBDMirrorActions(test_utils.PatchHelper): sorted(self.action_set.call_args[0][0]['output'].split('\n')), ['apool: Promoted 0 mirrored images', 'bpool: Promoted 0 mirrored images']) - self.action_get.side_effect = [True, True, False] + self.action_get.side_effect = [None, True, True, False] self.check_output.reset_mock() actions.rbd_mirror_action(['promote']) self.check_output.assert_has_calls([ @@ -90,6 +91,21 @@ class TestCephRBDMirrorActions(test_utils.PatchHelper): universal_newlines=True), ], any_order=True) self.action_get.assert_has_calls([ + mock.call('pools'), + mock.call('force'), + mock.call('verbose'), + mock.call('format'), + ]) + self.action_get.side_effect = ['apool', True, True, False] + self.check_output.reset_mock() + actions.rbd_mirror_action(['promote']) + self.check_output.assert_called_once_with( + ['rbd', '--id', 'acephid', 'mirror', 'pool', 'promote', + '--force', '--verbose', 'apool'], + stderr=actions.subprocess.STDOUT, + universal_newlines=True) + self.action_get.assert_has_calls([ + mock.call('pools'), mock.call('force'), mock.call('verbose'), mock.call('format'), @@ -123,16 +139,38 @@ class TestCephRBDMirrorActions(test_utils.PatchHelper): self.endpoint_from_name.return_value = endpoint self.crm_charm.eligible_pools.return_value = endpoint.pools self.crm_charm.ceph_id = 'acephid' - self.action_get.return_value = False + self.action_get.side_effect = [False, None] actions.resync_pools([]) + self.action_get.assert_has_calls([ + mock.call('i-really-mean-it'), + ]) self.assertFalse(self.check_output.called) self.assertFalse(self.action_set.called) - self.action_get.return_value = True - self.check_output.side_effect = [ - json.dumps(['imagea']), - 'resync flagged for imagea\n', - ] + self.action_get.side_effect = [True, 'bpool'] + self.check_output.return_value = json.dumps([]) actions.resync_pools([]) + self.action_get.assert_has_calls([ + mock.call('i-really-mean-it'), + mock.call('pools'), + ]) + self.check_output.assert_called_once_with( + ['rbd', '--id', 'acephid', '--format', 'json', + '-p', 'bpool', 'ls'], + universal_newlines=True) + self.action_set.assert_called_once_with({'output': ''}) + self.action_get.side_effect = [True, None] + self.check_output.side_effect = [ + json.dumps(['imagea', 'imageb']), + json.dumps({'mirroring': {'state': 'enabled'}}), + 'resync flagged for imagea\n', + json.dumps({'mirroring': {'state': 'disabled'}}), + ] + self.check_output.reset_mock() + actions.resync_pools([]) + self.action_get.assert_has_calls([ + mock.call('i-really-mean-it'), + mock.call('pools'), + ]) self.assertEquals( sorted(self.action_set.call_args[0][0]['output'].split('\n')), ['apool/imagea: resync flagged for imagea'])