Exemple #1
0
def test_rule_name_from_pv(
    fx_context,
    fx_volume_zone_label,
    fx_volume_annotation_provisioned_by,
    fx_annotation_deltas,
):
    volume_name = 'source-pv'

    annotations = {}
    annotations.update(fx_volume_annotation_provisioned_by)
    annotations.update(fx_annotation_deltas)

    source_pv = make_resource(
        pykube.objects.PersistentVolume,
        volume_name,
        annotations=annotations,
        labels=fx_volume_zone_label,
        spec={'gcePersistentDisk': {
            'pdName': 'source-pd'
        }})

    expected_rule_name = f'pv-{volume_name}'

    loop = asyncio.get_event_loop()
    with mock_kube([source_pv]):

        async def _run():
            rule = await rule_from_pv(ctx=fx_context,
                                      volume=source_pv,
                                      deltas_annotation_key=fx_context.
                                      config['deltas_annotation_key'])

            assert rule.name == expected_rule_name

        loop.run_until_complete(_run())
Exemple #2
0
def test_rule_name_from_pvc(fx_context, claim_namespace):
    claim_name = 'source-pvc'

    source_pv = make_resource(pykube.objects.PersistentVolume,
                              'source-pv',
                              annotations=ANNOTATION_PROVISIONED_BY,
                              labels=LABEL_ZONE,
                              spec={
                                  'claimRef': {
                                      'name': claim_name,
                                      'namespace': claim_namespace,
                                  },
                                  'gcePersistentDisk': {
                                      'pdName': 'source-pd',
                                  }
                              })

    source_pvc = make_resource(
        pykube.objects.PersistentVolumeClaim,
        claim_name,
        namespace=claim_namespace,
        annotations={fx_context.config['deltas_annotation_key']: 'PT1M PT2M'})

    resources = [source_pv, source_pvc]

    if claim_namespace == 'default':
        expected_rule_name = f'pvc-{claim_name}'
    else:
        expected_rule_name = f'{claim_namespace}-pvc-{claim_name}'

    loop = asyncio.get_event_loop()
    with mock_kube(resources):

        async def _run():
            rule = await rule_from_pv(ctx=fx_context,
                                      volume=source_pv,
                                      deltas_annotation_key=fx_context.
                                      config['deltas_annotation_key'])

            assert rule.name == expected_rule_name

        loop.run_until_complete(_run())
Exemple #3
0
def test_rule_from_volume(fx_context: Context, fx_deltas: str,
                          label_zone: Optional[Dict[str, str]],
                          annotation_provisioned_by: Optional[Dict[str, str]],
                          _spec_gce_persistent_disk: Optional[Dict[str, Any]]):
    annotations = {}

    annotations.update({
        fx_context.config['deltas_annotation_key']: fx_deltas,
    })

    if annotation_provisioned_by is not None:
        annotations.update(annotation_provisioned_by)

    labels = {}

    if label_zone is not None:
        labels.update(label_zone)

    spec = {}

    if _spec_gce_persistent_disk is not None:
        spec.update(_spec_gce_persistent_disk)

    source_pv = make_resource(
        pykube.objects.PersistentVolume,
        'source-pv',
        annotations=annotations,
        labels=labels,
        spec=spec,
    )

    expected_rule_name = f'pv-{source_pv.name}'

    loop = asyncio.get_event_loop()

    with mock_kube([source_pv]):
        rule: Rule = loop.run_until_complete(
            rule_from_pv(fx_context, source_pv,
                         fx_context.config['deltas_annotation_key']))
        assert rule.name == expected_rule_name
        assert rule.deltas == parse_deltas(fx_deltas)