ceph: add unit tests for object store controller with multisite
Add unit tests for when the "Zone" is configured in an object store so that the object store joins the CephObjectZone and the zone's corresponding multisite configuration. Signed-off-by: Ali Maredia <amaredia@redhat.com>
This commit is contained in:
1 parent
58ed572294
commit
8964941d44
3 files changed
+264
-4
No files matched your search
@@ -401,7 +401,8 @@ func (r *ReconcileCephObjectStore) reconcileCephZone(store *cephv1.CephObjectSto
|
||||
func (r *ReconcileCephObjectStore) reconcileMultisiteCRs(cephObjectStore *cephv1.CephObjectStore) (string, string, string, reconcile.Result, error) {
|
||||
if cephObjectStore.Spec.IsMultisite() {
|
||||
zoneName := cephObjectStore.Spec.Zone.Name
|
||||
zone, err := r.context.RookClientset.CephV1().CephObjectZones(cephObjectStore.Namespace).Get(zoneName, metav1.GetOptions{})
|
||||
zone := &cephv1.CephObjectZone{}
|
||||
err := r.client.Get(context.TODO(), types.NamespacedName{Name: zoneName, Namespace: cephObjectStore.Namespace}, zone)
|
||||
if err != nil {
|
||||
if kerrors.IsNotFound(err) {
|
||||
return "", "", "", waitForRequeueIfObjectStoreNotReady, err
|
||||
@@ -410,7 +411,8 @@ func (r *ReconcileCephObjectStore) reconcileMultisiteCRs(cephObjectStore *cephv1
|
||||
}
|
||||
logger.Debugf("CephObjectZone resource %s found", zone.Name)
|
||||
|
||||
zonegroup, err := r.context.RookClientset.CephV1().CephObjectZoneGroups(cephObjectStore.Namespace).Get(zone.Spec.ZoneGroup, metav1.GetOptions{})
|
||||
zonegroup := &cephv1.CephObjectZoneGroup{}
|
||||
err = r.client.Get(context.TODO(), types.NamespacedName{Name: zone.Spec.ZoneGroup, Namespace: cephObjectStore.Namespace}, zonegroup)
|
||||
if err != nil {
|
||||
if kerrors.IsNotFound(err) {
|
||||
return "", "", "", waitForRequeueIfObjectStoreNotReady, err
|
||||
@@ -419,7 +421,8 @@ func (r *ReconcileCephObjectStore) reconcileMultisiteCRs(cephObjectStore *cephv1
|
||||
}
|
||||
logger.Debugf("CephObjectZoneGroup resource %s found", zonegroup.Name)
|
||||
|
||||
realm, err := r.context.RookClientset.CephV1().CephObjectRealms(cephObjectStore.Namespace).Get(zonegroup.Spec.Realm, metav1.GetOptions{})
|
||||
realm := &cephv1.CephObjectRealm{}
|
||||
err = r.client.Get(context.TODO(), types.NamespacedName{Name: zonegroup.Spec.Realm, Namespace: cephObjectStore.Namespace}, realm)
|
||||
if err != nil {
|
||||
if kerrors.IsNotFound(err) {
|
||||
return "", "", "", waitForRequeueIfObjectStoreNotReady, err
|
||||
|
||||
@@ -175,6 +175,96 @@ const (
|
||||
"type": "rgw",
|
||||
"mfa_ids": []
|
||||
}`
|
||||
realmListMultisiteJSON = `{
|
||||
"default_info": "237e6250-5f7d-4b85-9359-8cb2b1848507",
|
||||
"realms": [
|
||||
"realm-a"
|
||||
]
|
||||
}`
|
||||
realmGetMultisiteJSON = `{
|
||||
"id": "237e6250-5f7d-4b85-9359-8cb2b1848507",
|
||||
"name": "realm-a",
|
||||
"current_period": "df665ecb-1762-47a9-9c66-f938d251c02a",
|
||||
"epoch": 2
|
||||
}`
|
||||
zoneGroupGetMultisiteJSON = `{
|
||||
"id": "fd8ff110-d3fd-49b4-b24f-f6cd3dddfedf",
|
||||
"name": "zonegroup-a",
|
||||
"api_name": "zonegroup-a",
|
||||
"is_master": "true",
|
||||
"endpoints": [
|
||||
":80"
|
||||
],
|
||||
"hostnames": [],
|
||||
"hostnames_s3website": [],
|
||||
"master_zone": "6cb39d2c-3005-49da-9be3-c1a92a97d28a",
|
||||
"zones": [
|
||||
{
|
||||
"id": "6cb39d2c-3005-49da-9be3-c1a92a97d28a",
|
||||
"name": "zone-a",
|
||||
"endpoints": [
|
||||
":80"
|
||||
],
|
||||
"log_meta": "false",
|
||||
"log_data": "false",
|
||||
"bucket_index_max_shards": 0,
|
||||
"read_only": "false",
|
||||
"tier_type": "",
|
||||
"sync_from_all": "true",
|
||||
"sync_from": [],
|
||||
"redirect_zone": ""
|
||||
}
|
||||
],
|
||||
"placement_targets": [
|
||||
{
|
||||
"name": "default-placement",
|
||||
"tags": [],
|
||||
"storage_classes": [
|
||||
"STANDARD"
|
||||
]
|
||||
}
|
||||
],
|
||||
"default_placement": "default-placement",
|
||||
"realm_id": "237e6250-5f7d-4b85-9359-8cb2b1848507"
|
||||
}`
|
||||
zoneGetMultisiteJSON = `{
|
||||
"id": "6cb39d2c-3005-49da-9be3-c1a92a97d28a",
|
||||
"name": "zone-a",
|
||||
"domain_root": "my-store.rgw.meta:root",
|
||||
"control_pool": "my-store.rgw.control",
|
||||
"gc_pool": "my-store.rgw.log:gc",
|
||||
"lc_pool": "my-store.rgw.log:lc",
|
||||
"log_pool": "my-store.rgw.log",
|
||||
"intent_log_pool": "my-store.rgw.log:intent",
|
||||
"usage_log_pool": "my-store.rgw.log:usage",
|
||||
"reshard_pool": "my-store.rgw.log:reshard",
|
||||
"user_keys_pool": "my-store.rgw.meta:users.keys",
|
||||
"user_email_pool": "my-store.rgw.meta:users.email",
|
||||
"user_swift_pool": "my-store.rgw.meta:users.swift",
|
||||
"user_uid_pool": "my-store.rgw.meta:users.uid",
|
||||
"otp_pool": "my-store.rgw.otp",
|
||||
"system_key": {
|
||||
"access_key": "",
|
||||
"secret_key": ""
|
||||
},
|
||||
"placement_pools": [
|
||||
{
|
||||
"key": "default-placement",
|
||||
"val": {
|
||||
"index_pool": "my-store.rgw.buckets.index",
|
||||
"storage_classes": {
|
||||
"STANDARD": {
|
||||
"data_pool": "my-store.rgw.buckets.data"
|
||||
}
|
||||
},
|
||||
"data_extra_pool": "my-store.rgw.buckets.non-ec",
|
||||
"index_type": 0
|
||||
}
|
||||
}
|
||||
],
|
||||
"metadata_heap": "",
|
||||
"realm_id": ""
|
||||
}`
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -398,3 +488,170 @@ func TestCephObjectStoreController(t *testing.T) {
|
||||
assert.False(t, okToDelete)
|
||||
logger.Info("PHASE 4 DONE")
|
||||
}
|
||||
|
||||
func TestCephObjectStoreControllerMultisite(t *testing.T) {
|
||||
capnslog.SetGlobalLogLevel(capnslog.DEBUG)
|
||||
os.Setenv("ROOK_LOG_LEVEL", "DEBUG")
|
||||
|
||||
zoneName := "zone-a"
|
||||
zoneGroupName := "zonegroup-a"
|
||||
realmName := "realm-a"
|
||||
|
||||
metadataPool := cephv1.PoolSpec{}
|
||||
dataPool := cephv1.PoolSpec{}
|
||||
|
||||
cephCluster := &cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: namespace,
|
||||
Namespace: namespace,
|
||||
},
|
||||
Status: cephv1.ClusterStatus{
|
||||
Phase: k8sutil.ReadyStatus,
|
||||
CephStatus: &cephv1.CephStatus{
|
||||
Health: "HEALTH_OK",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
secrets := map[string][]byte{
|
||||
"fsid": []byte(name),
|
||||
"mon-secret": []byte("monsecret"),
|
||||
"admin-secret": []byte("adminsecret"),
|
||||
}
|
||||
secret := &v1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "rook-ceph-mon",
|
||||
Namespace: namespace,
|
||||
},
|
||||
Data: secrets,
|
||||
Type: k8sutil.RookType,
|
||||
}
|
||||
|
||||
objectZone := &cephv1.CephObjectZone{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: zoneName,
|
||||
Namespace: namespace,
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "CephObjectZone",
|
||||
},
|
||||
Spec: cephv1.ObjectZoneSpec{
|
||||
ZoneGroup: zoneGroupName,
|
||||
MetadataPool: metadataPool,
|
||||
DataPool: dataPool,
|
||||
},
|
||||
}
|
||||
|
||||
objectZoneGroup := &cephv1.CephObjectZoneGroup{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: zoneGroupName,
|
||||
Namespace: namespace,
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "CephObjectZoneGroup",
|
||||
},
|
||||
Spec: cephv1.ObjectZoneGroupSpec{},
|
||||
}
|
||||
|
||||
objectZoneGroup.Spec.Realm = realmName
|
||||
|
||||
objectRealm := &cephv1.CephObjectRealm{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: realmName,
|
||||
Namespace: namespace,
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "CephObjectRealm",
|
||||
},
|
||||
Spec: cephv1.ObjectRealmSpec{},
|
||||
}
|
||||
|
||||
objectStore := &cephv1.CephObjectStore{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: store,
|
||||
Namespace: namespace,
|
||||
},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "CephObjectStore",
|
||||
},
|
||||
Spec: cephv1.ObjectStoreSpec{},
|
||||
}
|
||||
|
||||
objectStore.Spec.Zone.Name = zoneName
|
||||
objectStore.Spec.Gateway.Port = 80
|
||||
|
||||
object := []runtime.Object{
|
||||
objectZone,
|
||||
objectStore,
|
||||
objectZoneGroup,
|
||||
objectRealm,
|
||||
cephCluster,
|
||||
}
|
||||
|
||||
executor := &exectest.MockExecutor{
|
||||
MockExecuteCommandWithOutputFile: func(command, outfile string, args ...string) (string, error) {
|
||||
if args[0] == "status" {
|
||||
return `{"fsid":"c47cac40-9bee-4d52-823b-ccd803ba5bfe","health":{"checks":{},"status":"HEALTH_OK"},"pgmap":{"num_pgs":100,"pgs_by_state":[{"state_name":"active+clean","count":100}]}}`, nil
|
||||
}
|
||||
if args[0] == "auth" && args[1] == "get-or-create-key" {
|
||||
return rgwCephAuthGetOrCreateKey, nil
|
||||
}
|
||||
if args[0] == "versions" {
|
||||
return dummyVersionsRaw, nil
|
||||
}
|
||||
return "", nil
|
||||
},
|
||||
MockExecuteCommandWithOutput: func(command string, args ...string) (string, error) {
|
||||
if args[0] == "realm" && args[1] == "list" {
|
||||
return realmListMultisiteJSON, nil
|
||||
}
|
||||
if args[0] == "realm" && args[1] == "get" {
|
||||
return realmGetMultisiteJSON, nil
|
||||
}
|
||||
if args[0] == "zonegroup" && args[1] == "get" {
|
||||
return zoneGroupGetMultisiteJSON, nil
|
||||
}
|
||||
if args[0] == "zone" && args[1] == "get" {
|
||||
return zoneGetMultisiteJSON, nil
|
||||
}
|
||||
return "", nil
|
||||
},
|
||||
}
|
||||
|
||||
clientset := test.New(t, 3)
|
||||
c := &clusterd.Context{
|
||||
Executor: executor,
|
||||
RookClientset: rookclient.NewSimpleClientset(),
|
||||
Clientset: clientset,
|
||||
}
|
||||
|
||||
// Register operator types with the runtime scheme.
|
||||
s := scheme.Scheme
|
||||
s.AddKnownTypes(cephv1.SchemeGroupVersion, &cephv1.CephObjectZone{}, &cephv1.CephObjectZoneList{}, &cephv1.CephCluster{}, &cephv1.CephClusterList{}, &cephv1.CephObjectStore{}, &cephv1.CephObjectStoreList{})
|
||||
|
||||
// Create a fake client to mock API calls.
|
||||
cl := fake.NewFakeClientWithScheme(s, object...)
|
||||
|
||||
r := &ReconcileCephObjectStore{
|
||||
client: cl,
|
||||
scheme: s,
|
||||
context: c,
|
||||
objectStoreChannels: make(map[string]*objectStoreHealth),
|
||||
}
|
||||
|
||||
_, err := r.context.Clientset.CoreV1().Secrets(namespace).Create(secret)
|
||||
assert.NoError(t, err)
|
||||
|
||||
req := reconcile.Request{
|
||||
NamespacedName: types.NamespacedName{
|
||||
Name: store,
|
||||
Namespace: namespace,
|
||||
},
|
||||
}
|
||||
|
||||
res, err := r.Reconcile(req)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, res.Requeue)
|
||||
err = r.client.Get(context.TODO(), req.NamespacedName, objectStore)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -297,7 +297,7 @@ func (r *ReconcileObjectZone) reconcileObjectZoneGroup(zone *cephv1.CephObjectZo
|
||||
return "", waitForRequeueIfObjectZoneGroupNotReady, errors.Wrapf(err, "error getting cephObjectZoneGroup %v", zone.Spec.ZoneGroup)
|
||||
}
|
||||
|
||||
logger.Infof("CephObjectZoneGroup %v found", zoneGroup.Name)
|
||||
logger.Debugf("CephObjectZoneGroup %v found", zoneGroup.Name)
|
||||
return zoneGroup.Spec.Realm, reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user