Esempio n. 1
0
def test_delete_deployment(client, api):
    depl1 = V1Deployment(metadata=V1ObjectMeta(name="depl1"))
    depl2 = V1Deployment(metadata=V1ObjectMeta(name="depl2"))
    v1 = MagicMock()
    client.AppsV1beta1Api.return_value = v1
    v1.list_namespaced_deployment.return_value = V1DeploymentList(
        items=(depl1, depl2))

    delete_deployment("fake_name", "fake_ns")

    v1.list_namespaced_deployment.assert_called_with("fake_ns",
                                                     label_selector=ANY)
    v1.delete_namespaced_deployment.assert_has_calls(calls=[
        call(depl1.metadata.name, "fake_ns", body=ANY),
        call(depl2.metadata.name, "fake_ns", body=ANY)
    ],
                                                     any_order=True)
Esempio n. 2
0
            }
        }
    }
}

test_dep = V1Deployment(
    'apps/v1', 
    'Deployment', 
    V1ObjectMeta(name='web-main', labels={'app': 'web'}, annotations={'opsani-current-mode': 'canary'}), 
    V1DeploymentSpec(
        replicas=3,
        selector=V1LabelSelector(match_labels={'app': 'web', 'role': 'main'}),
        template=V1PodTemplateSpec(
            metadata=V1ObjectMeta(labels={'app': 'web', 'role': 'main'}),
            spec=V1PodSpec(containers=[V1Container(
                name='main',
                image='opsani/co-http:latest',
                args=['busy=400'],
                resources=V1ResourceRequirements(
                    limits={'cpu': '125m', 'memory': '512Mi'},
                    requests={'cpu': '125m', 'memory': '512Mi'}
                ),
                ports=[V1ContainerPort(container_port=8080)]
            )])
        )
    )
)

def setup_module(module):
    if os.getenv('KUBERNETES_SERVICE_HOST'): # If running in a kubernetes cluster
        kubernetes.config.load_incluster_config()
    else: