How to use delete_deployment method in localstack

Best Python code snippet using localstack_python

test_deployments.py

Source:test_deployments.py Github

copy

Full Screen

1# All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License"); you may4# not use this file except in compliance with the License. You may obtain5# a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12# License for the specific language governing permissions and limitations13# under the License.14import mock15from kubernetes.client import rest16from tests.unit import test17from xrally_kubernetes.tasks.scenarios import deployments18class CreateAndDeleteDeploymentTestCase(test.TestCase):19 def setUp(self):20 super(CreateAndDeleteDeploymentTestCase, self).setUp()21 self.scenario = deployments.CreateAndDeleteDeployment()22 self.client = mock.MagicMock()23 self.scenario.client = self.client24 self.scenario.context = {25 "iteration": 1,26 "kubernetes": {27 "namespaces": ["ns"],28 "namespace_choice_method": "round_robin"29 }30 }31 def test_create_and_delete_success(self):32 self.client.create_deployment.return_value = "test"33 self.scenario.run("test/image", 2, command=["ls"])34 self.client.create_deployment.assert_called_once_with(35 namespace="ns",36 image="test/image",37 replicas=2,38 command=["ls"],39 status_wait=True40 )41 self.client.delete_deployment.assert_called_once_with(42 "test",43 namespace="ns",44 status_wait=True45 )46 def test_create_failed(self):47 self.client.create_deployment.side_effect = [48 rest.ApiException(status=500, reason="Test")49 ]50 self.assertRaises(rest.ApiException, self.scenario.run,51 "test/image", 2)52 self.client.create_deployment.assert_called_once_with(53 namespace="ns",54 image="test/image",55 replicas=2,56 command=None,57 status_wait=True58 )59 self.assertEqual(0, self.client.delete_deployment.call_count)60 def test_delete_failed(self):61 self.client.create_deployment.return_value = "test"62 self.client.delete_deployment.side_effect = [63 rest.ApiException(status=500, reason="Test")64 ]65 self.assertRaises(rest.ApiException, self.scenario.run,66 "test/image", 2)67 self.client.create_deployment.assert_called_once_with(68 command=None,69 namespace="ns",70 replicas=2,71 image="test/image",72 status_wait=True73 )74class CreateRolloutAndDeleteReplicaSetTestCase(test.TestCase):75 def setUp(self):76 super(CreateRolloutAndDeleteReplicaSetTestCase, self).setUp()77 self.scenario = deployments.CreateRolloutAndDeleteDeployment()78 self.client = mock.MagicMock()79 self.scenario.client = self.client80 self.scenario.context = {81 "iteration": 1,82 "kubernetes": {83 "namespaces": ["ns"],84 "namespace_choice_method": "round_robin"85 }86 }87 def test_create_and_delete_success(self):88 self.client.create_deployment.return_value = "test"89 self.scenario.run("test/image", 2, command=["ls"],90 changes={"image": "test/image2"})91 self.client.create_deployment.assert_called_once_with(92 namespace="ns",93 env=None,94 image="test/image",95 replicas=2,96 command=["ls"],97 resources=None,98 status_wait=True99 )100 self.client.rollout_deployment.assert_called_once_with(101 "test",102 namespace="ns",103 replicas=2,104 changes={"image": "test/image2"},105 status_wait=True106 )107 self.client.delete_deployment.assert_called_once_with(108 name="test",109 namespace="ns",110 status_wait=True111 )112 def test_create_failed(self):113 self.client.create_deployment.side_effect = [114 rest.ApiException(status=500, reason="Test")115 ]116 self.assertRaises(rest.ApiException, self.scenario.run,117 "test/image", 2, changes={"image": "test/image2"})118 self.client.create_deployment.assert_called_once_with(119 namespace="ns",120 env=None,121 image="test/image",122 replicas=2,123 command=None,124 resources=None,125 status_wait=True126 )127 self.assertEqual(0, self.client.rollout_deployment.call_count)128 self.assertEqual(0, self.client.delete_deployment.call_count)129 def test_rollout_failed(self):130 self.client.create_deployment.return_value = "test"131 self.client.rollout_deployment.side_effect = [132 rest.ApiException(status=500, reason="Test")133 ]134 self.assertRaises(rest.ApiException, self.scenario.run,135 "test/image", 2, changes={"image": "test/image2"})136 self.client.create_deployment.assert_called_once_with(137 namespace="ns",138 env=None,139 image="test/image",140 replicas=2,141 command=None,142 resources=None,143 status_wait=True144 )145 self.client.rollout_deployment.assert_called_once_with(146 "test",147 namespace="ns",148 replicas=2,149 changes={"image": "test/image2"},150 status_wait=True151 )152 self.assertEqual(0, self.client.delete_deployment.call_count)153 def test_delete_failed(self):154 self.client.create_deployment.return_value = "test"155 self.client.delete_deployment.side_effect = [156 rest.ApiException(status=500, reason="Test")157 ]158 self.assertRaises(rest.ApiException, self.scenario.run,159 "test/image", 2, changes={"image": "test/image2"})160 self.client.create_deployment.assert_called_once_with(161 namespace="ns",162 env=None,163 image="test/image",164 replicas=2,165 command=None,166 resources=None,167 status_wait=True168 )...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...41 name=deployment_name,42 namespace="default",43 body=deployment)44 print("Deployment updated. status='%s'" % str(api_response.status))45def delete_deployment(api_instance, deployment_name):46 # Delete deployment47 api_response = api_instance.delete_namespaced_deployment(48 name=deployment_name,49 namespace="default",50 body=client.V1DeleteOptions(51 propagation_policy='Foreground',52 grace_period_seconds=5))53 print("Deployment deleted. status='%s'" % str(api_response.status))54# Create an instance of the API class55config.load_kube_config()56apps_v1 = client.AppsV1Api()57# Getting the deployment58deployment_name = "kube-znn"59deployment_image = "cmendes/znn:100k"60deployment_replicas = 261current_deployment = apps_v1.read_namespaced_deployment("kube-znn", "default")62#current_deployment.spec.replicas = 063#update_deployment(apps_v1, current_deployment, deployment_name, deployment_image)64#current_deployment.spec.replicas = deployment_replicas65update_deployment(apps_v1, current_deployment, deployment_name, deployment_image)66#delete_deployment(apps_v1, deployment_name)67#deployament = create_deployment_object(deployment_name, deployment_image, deployment_replicas)68#create_deployment(apps_v1, deployament)69#delete_deployment(apps_v1, deployment_name)70#deployment_name = "kube-znn"71#deployment_image = "cmendes/kube-znn:text"72#deployment_replicas = 273#deployment = create_deployment_object(deployment_name, deployment_image, deployment_replicas)74#create_deployment(apps_v1, deployment)75#print("finished!")76#current_deployment = apps_v1.read_namespaced_deployment("kube-znn", "default")77#current_deployment.spec.template.spec.containers[0].image = "cmendes/kube-znn:text"78#created_object = create_deployment_object(current_deployment)79#delete_deployment(apps_v1, current_deployment)80#create_deployment(apps_v1, created_object)81#print(deployment.metadata.name)82#print(deployment.spec.template.spec.containers[0].image)83#print(deployment.spec.replicas)84#print(deployment)85# Rollout86#deployment.spec.replicas = 087#update_deployment(apps_v1, deployment)88#deployment.spec.template.spec.containers[0].image = "cmendes/kube-znn:text"89#deployment.spec.replicas = 290#update_deployment(apps_v1, deployment)91# Scale92#deployment.spec.replicas = 293#update_deployment(apps_v1, deployment)

Full Screen

Full Screen

test_delete.py

Source:test_delete.py Github

copy

Full Screen

...14 assert delete_deployment.body_parameters() == {}15@unittest.mock.patch('requests.Session.request')16def test_get_calls_requests(mock, engine_url):17 delete_deployment = pycamunda.deployment.Delete(url=engine_url, id_='anId')18 delete_deployment()19 assert mock.called20 assert mock.call_args[1]['method'].upper() == 'DELETE'21@unittest.mock.patch('requests.Session.request', raise_requests_exception_mock)22def test_get_raises_pycamunda_exception(engine_url):23 delete_deployment = pycamunda.deployment.Delete(url=engine_url, id_='anId')24 with pytest.raises(pycamunda.PyCamundaException):25 delete_deployment()26@unittest.mock.patch('requests.Session.request', not_ok_response_mock)27@unittest.mock.patch('pycamunda.base._raise_for_status')28def test_get_raises_for_status(mock, engine_url):29 delete_deployment = pycamunda.deployment.Delete(url=engine_url, id_='anId')30 delete_deployment()31 assert mock.called32@unittest.mock.patch('requests.Session.request', unittest.mock.MagicMock())33def test_get_returns_none(engine_url):34 delete_deployment = pycamunda.deployment.Delete(url=engine_url, id_='anId')35 result = delete_deployment()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful