def test_get_by_name_nonexistent(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         result = K8sDeployment.get_by_name(config=dep.config, name=name)
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
Exemplo n.º 2
0
 def test_list_nonexistent(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         objs = dep.list()
         self.assertIsInstance(objs, list)
         self.assertEqual(0, len(objs))
Exemplo n.º 3
0
 def test_get_by_name_nonexistent(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         result = K8sDeployment.get_by_name(config=dep.config, name=name)
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
 def test_list_nonexistent(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         objs = dep.list()
         self.assertIsInstance(objs, list)
         self.assertEqual(0, len(objs))
 def test_rollback_no_args(self):
     name = "nginx"
     image1 = "nginx:1.7.9"
     image2 = "nginx:1.9.1"
     container = utils.create_container(name=name, image=image1)
     dep_name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=dep_name)
     dep.add_container(container)
     dep.desired_replicas = 3
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         self.assertEqual(image1, dep.containers[0].image)
         dep.container_image = (name, image2)
         dep.update()
         self.assertIn('deployment.kubernetes.io/revision', dep.annotations)
         rev_before = dep.get_annotation(
             'deployment.kubernetes.io/revision')
         self.assertNotEqual(image1, dep.containers[0].image)
         self.assertEqual(image2, dep.containers[0].image)
         dep.rollback()
         self.assertIn('deployment.kubernetes.io/revision', dep.annotations)
         rev_after = dep.get_annotation('deployment.kubernetes.io/revision')
         self.assertNotEqual(rev_before, rev_after)
         self.assertGreater(rev_after, rev_before)
         self.assertEqual(image1, dep.containers[0].image)
         self.assertNotEqual(image2, dep.containers[0].image)
Exemplo n.º 6
0
 def test_delete_nonexistent(self):
     name = "yorc-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         try:
             dep.delete()
             self.fail("Should not fail.")
         except Exception as err:
             self.assertIsInstance(err, NotFoundException)
 def test_delete_nonexistent(self):
     name = "yorc-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         try:
             dep.delete()
             self.fail("Should not fail.")
         except Exception as err:
             self.assertIsInstance(err, NotFoundException)
 def test_update_namespace_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yorc-{0}".format(str(uuid.uuid4()))
     nspace = "yonamespace"
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         dep.namespace = nspace
         with self.assertRaises(BadRequestException):
             dep.update()
 def test_delete(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         utils.cleanup_deployments()
         result = dep.list()
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
Exemplo n.º 10
0
 def test_update_namespace_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yorc-{0}".format(str(uuid.uuid4()))
     nspace = "yonamespace"
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         dep.set_namespace(nspace)
         with self.assertRaises(BadRequestException):
             dep.update()
Exemplo n.º 11
0
 def test_create_already_exists(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "nginx"
     cont_image = "nginx:1.7.9"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     dep.set_replicas(1)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         with self.assertRaises(AlreadyExistsException):
             dep.create()
 def test_update_name_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name1 = "yodep1"
     name2 = "yodep2"
     dep = utils.create_deployment(name=name1)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         dep.name = name2
         with self.assertRaises(NotFoundException):
             dep.update()
Exemplo n.º 13
0
 def test_update_name_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name1 = "yodep1"
     name2 = "yodep2"
     dep = utils.create_deployment(name=name1)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         dep.name = name2
         with self.assertRaises(BadRequestException):
             dep.update()
Exemplo n.º 14
0
 def test_delete(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         utils.cleanup_deployments()
         result = dep.list()
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
 def test_create_already_exists(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "nginx"
     cont_image = "nginx:1.7.9"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     dep.desired_replicas = 1
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         with self.assertRaises(AlreadyExistsException):
             dep.create()
Exemplo n.º 16
0
 def test_get_by_name(self):
     cont_name = "yocontainer"
     container = utils.create_container(name=cont_name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         result = K8sDeployment.get_by_name(config=dep.config, name=name)
         self.assertIsInstance(result, list)
         self.assertEqual(1, len(result))
         self.assertIsInstance(result[0], K8sDeployment)
         self.assertEqual(dep, result[0])
 def test_get_by_name(self):
     cont_name = "yocontainer"
     container = utils.create_container(name=cont_name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         result = K8sDeployment.get_by_name(config=dep.config, name=name)
         self.assertIsInstance(result, list)
         self.assertEqual(1, len(result))
         self.assertIsInstance(result[0], K8sDeployment)
         self.assertEqual(dep, result[0])
 def test_update_pod_labels(self):
     name = "nginx"
     image = "nginx:1.7.9"
     container = utils.create_container(name=name, image=image)
     dep_name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=dep_name)
     dep.add_container(container)
     dep.desired_replicas = 3
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         labels = dep.pod_labels
         labels['newkey'] = 'newvalue'
         dep.pod_labels = labels
         updated = dep.update()
         self.assertEqual(labels, updated.pod_labels)
Exemplo n.º 19
0
 def test_update_pod_labels(self):
     name = "nginx"
     image = "nginx:1.7.9"
     container = utils.create_container(name=name, image=image)
     dep_name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=dep_name)
     dep.add_container(container)
     dep.set_replicas(3)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         labels = dep.get_pod_labels()
         labels['newkey'] = 'newvalue'
         dep.set_pod_labels(labels)
         updated = dep.update()
         self.assertEqual(labels, updated.get_pod_labels())
 def test_create_one_replica(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "nginx"
     cont_image = "nginx:1.7.9"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     dep.desired_replicas = 1
     if utils.is_reachable(dep.config.api_host):
         d = dep.create()
         self.assertIsNotNone(d)
         self.assertIsInstance(d, K8sDeployment)
         self.assertEqual(d, dep)
         self.assertEqual(1, d.desired_replicas)
         self.assertEqual(1, d.available_replicas)
         self.assertEqual(1, d.updated_replicas)
Exemplo n.º 21
0
 def test_create_zero_replicas(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "redis"
     cont_image = "redis:3.2.3"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     if utils.is_reachable(dep.config.api_host):
         d = dep.create()
         self.assertIsNotNone(d)
         self.assertIsInstance(d, K8sDeployment)
         self.assertEqual(d, dep)
         self.assertEqual(0, d.model.model['spec']['replicas'])
         self.assertNotIn('replicas', d.model.model['status'])
         self.assertNotIn('availableReplicas', d.model.model['status'])
         self.assertNotIn('updatedReplicas', d.model.model['status'])
Exemplo n.º 22
0
 def test_create_three_replicas(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "nginx"
     cont_image = "nginx:1.7.9"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     dep.set_replicas(3)
     if utils.is_reachable(dep.config.api_host):
         d = dep.create()
         self.assertIsNotNone(d)
         self.assertIsInstance(d, K8sDeployment)
         self.assertEqual(d, dep)
         self.assertEqual(3, d.model.model['status']['replicas'])
         self.assertEqual(3, d.model.model['status']['availableReplicas'])
         self.assertEqual(3, d.model.model['status']['updatedReplicas'])
 def test_scale(self):
     cont_name = "yocontainer"
     container = utils.create_container(name=cont_name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     dep.desired_replicas = 3
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         self.assertEqual(3, dep.desired_replicas)
         self.assertEqual(3, dep.updated_replicas)
         self.assertEqual(3, dep.available_replicas)
         dep.scale(5)
         self.assertEqual(5, dep.desired_replicas)
         self.assertEqual(5, dep.updated_replicas)
         self.assertEqual(5, dep.available_replicas)
Exemplo n.º 24
0
 def test_scale(self):
     cont_name = "yocontainer"
     container = utils.create_container(name=cont_name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     dep.set_replicas(3)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         replicas = dep.get_replicas()
         for k in replicas:
             self.assertEqual(3, replicas[k])
         dep.scale(5)
         replicas = dep.get_replicas()
         for k in replicas:
             self.assertEqual(5, replicas[k])
 def test_create_zero_replicas(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "redis"
     cont_image = "redis:3.2.3"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     if utils.is_reachable(dep.config.api_host):
         d = dep.create()
         self.assertIsNotNone(d)
         self.assertIsInstance(d, K8sDeployment)
         self.assertEqual(d, dep)
         self.assertEqual(0, d.desired_replicas)
         self.assertIsNone(d.available_replicas)
         self.assertIsNone(d.current_replicas)
         self.assertIsNone(d.unavailable_replicas)
         self.assertIsNone(d.updated_replicas)
Exemplo n.º 26
0
 def test_update_container_image(self):
     name = "nginx"
     image1 = "nginx:1.7.9"
     image2 = "nginx:1.9.1"
     container = utils.create_container(name=name, image=image1)
     dep_name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=dep_name)
     dep.add_container(container)
     dep.set_replicas(3)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         self.assertEqual(image1, dep.model.model['spec']['template']['spec']['containers'][0]['image'])
         dep.set_container_image(name=name, image=image2)
         dep.update()
         self.assertIn('annotations', dep.model.deployment_metadata.model)
         self.assertIn('deployment.kubernetes.io/revision', dep.model.deployment_metadata.model['annotations'])
         self.assertNotEqual(image1, dep.model.model['spec']['template']['spec']['containers'][0]['image'])
         self.assertEqual(image2, dep.model.model['spec']['template']['spec']['containers'][0]['image'])
 def test_list_multiple(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     config = K8sConfig(kubeconfig=utils.kubeconfig_fallback)
     deployments = []
     count = 3
     objs = []
     if utils.is_reachable(config.api_host):
         for i in range(0, count):
             name = "yodep-{0}".format(str(uuid.uuid4()))
             dep = utils.create_deployment(config, name)
             dep.add_container(container)
             result = dep.create()
             self.assertIsInstance(result, K8sDeployment)
             self.assertEqual(dep, result)
             deployments.append(dep)
             objs = dep.list()
         self.assertEqual(count, len(deployments))
         self.assertEqual(count, len(objs))
Exemplo n.º 28
0
 def test_list_multiple(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     config = K8sConfig(kubeconfig=utils.kubeconfig_fallback)
     deployments = []
     count = 3
     objs = []
     if utils.is_reachable(config.api_host):
         for i in range(0, count):
             name = "yodep-{0}".format(str(uuid.uuid4()))
             dep = utils.create_deployment(config, name)
             dep.add_container(container)
             result = dep.create()
             self.assertIsInstance(result, K8sDeployment)
             self.assertEqual(dep, result)
             deployments.append(dep)
             objs = dep.list()
         self.assertEqual(count, len(deployments))
         self.assertEqual(count, len(objs))
Exemplo n.º 29
0
import utils, yaml, time, logging, charts





config.load_kube_config()
deployment_api = client.AppsV1Api()
customobject_api = client.CustomObjectsApi()
services = ["frontend", "adservice", "checkoutservice", "recommendationservice", "cartservice", "shippingservice", "emailservice", "paymentservice", "currencyservice", "productcatalogservice"]
logging.basicConfig(format='%(asctime)s - [%(levelname)s]  %(message)s', datefmt='%d/%m/%Y %I:%M:%S', level=logging.INFO)

for service in services:
    with open('../yaml-files/Deployment/'+service+'.yaml') as f:
        dep = yaml.safe_load(f)
        utils.create_deployment(deployment_api, dep, cpu="300m")
with open('../yaml-files/Deployment/redis-cart.yaml') as f:
    dep = yaml.safe_load(f)
    utils.create_deployment(deployment_api, dep, cpu="300m")


logging.info("All services are deployed successfully with CPU allocation 300m - Wait for 120 seconds to for all pods "
             "to be running")
time.sleep(120)

rpss = [200]
cbs = [0 ,5, 10, 20, 50, 100, 150]
retrys = [1, 2, 5, 10]
retry_timeouts = ["1s", "2s", "3s", "5s", "10s"]

for cb in cbs:
Exemplo n.º 30
0
 def test_create_no_args(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         with self.assertRaises(UnprocessableEntityException):
             dep.create()
Exemplo n.º 31
0
 def test_init_with_name(self):
     name = "yomama"
     dep = utils.create_deployment(name=name)
     self.assertIsNotNone(dep)
     self.assertIsInstance(dep, K8sDeployment)
     self.assertEqual(dep.name, name)
 def test_init_with_name(self):
     name = "yomama"
     dep = utils.create_deployment(name=name)
     self.assertIsNotNone(dep)
     self.assertIsInstance(dep, K8sDeployment)
     self.assertEqual(dep.name, name)
 def test_create_no_args(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         with self.assertRaises(UnprocessableEntityException):
             dep.create()
Exemplo n.º 34
0
 def test_delete_nonexistent(self):
     name = "yorc-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         with self.assertRaises(NotFoundException):
             dep.delete()
 def test_delete_nonexistent(self):
     name = "yorc-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         with self.assertRaises(NotFoundException):
             dep.delete()