Best Python code snippet using tempest_python
test_hypervisor_negative.py
Source:test_hypervisor_negative.py
1# Copyright 2013 Huawei Technologies Co.,LTD.2# All Rights Reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15import uuid16from tempest_lib import exceptions as lib_exc17from tempest.api.compute import base18from tempest.common.utils import data_utils19from tempest import test20class HypervisorAdminNegativeTestJSON(base.BaseV2ComputeAdminTest):21 """Tests Hypervisors API that require admin privileges"""22 @classmethod23 def setup_clients(cls):24 super(HypervisorAdminNegativeTestJSON, cls).setup_clients()25 cls.client = cls.os_adm.hypervisor_client26 cls.non_adm_client = cls.hypervisor_client27 def _list_hypervisors(self):28 # List of hypervisors29 hypers = self.client.list_hypervisors()['hypervisors']30 return hypers31 @test.attr(type=['negative'])32 @test.idempotent_id('c136086a-0f67-4b2b-bc61-8482bd68989f')33 def test_show_nonexistent_hypervisor(self):34 nonexistent_hypervisor_id = str(uuid.uuid4())35 self.assertRaises(36 lib_exc.NotFound,37 self.client.show_hypervisor,38 nonexistent_hypervisor_id)39 @test.attr(type=['negative'])40 @test.idempotent_id('51e663d0-6b89-4817-a465-20aca0667d03')41 def test_show_hypervisor_with_non_admin_user(self):42 hypers = self._list_hypervisors()43 self.assertTrue(len(hypers) > 0)44 self.assertRaises(45 lib_exc.Forbidden,46 self.non_adm_client.show_hypervisor,47 hypers[0]['id'])48 @test.attr(type=['negative'])49 @test.idempotent_id('2a0a3938-832e-4859-95bf-1c57c236b924')50 def test_show_servers_with_non_admin_user(self):51 hypers = self._list_hypervisors()52 self.assertTrue(len(hypers) > 0)53 self.assertRaises(54 lib_exc.Forbidden,55 self.non_adm_client.list_servers_on_hypervisor,56 hypers[0]['id'])57 @test.attr(type=['negative'])58 @test.idempotent_id('02463d69-0ace-4d33-a4a8-93d7883a2bba')59 def test_show_servers_with_nonexistent_hypervisor(self):60 nonexistent_hypervisor_id = str(uuid.uuid4())61 self.assertRaises(62 lib_exc.NotFound,63 self.client.list_servers_on_hypervisor,64 nonexistent_hypervisor_id)65 @test.attr(type=['negative'])66 @test.idempotent_id('e2b061bb-13f9-40d8-9d6e-d5bf17595849')67 def test_get_hypervisor_stats_with_non_admin_user(self):68 self.assertRaises(69 lib_exc.Forbidden,70 self.non_adm_client.show_hypervisor_statistics)71 @test.attr(type=['negative'])72 @test.idempotent_id('f60aa680-9a3a-4c7d-90e1-fae3a4891303')73 def test_get_nonexistent_hypervisor_uptime(self):74 nonexistent_hypervisor_id = str(uuid.uuid4())75 self.assertRaises(76 lib_exc.NotFound,77 self.client.show_hypervisor_uptime,78 nonexistent_hypervisor_id)79 @test.attr(type=['negative'])80 @test.idempotent_id('6c3461f9-c04c-4e2a-bebb-71dc9cb47df2')81 def test_get_hypervisor_uptime_with_non_admin_user(self):82 hypers = self._list_hypervisors()83 self.assertTrue(len(hypers) > 0)84 self.assertRaises(85 lib_exc.Forbidden,86 self.non_adm_client.show_hypervisor_uptime,87 hypers[0]['id'])88 @test.attr(type=['negative'])89 @test.idempotent_id('51b3d536-9b14-409c-9bce-c6f7c794994e')90 def test_get_hypervisor_list_with_non_admin_user(self):91 # List of hypervisor and available services with non admin user92 self.assertRaises(93 lib_exc.Forbidden,94 self.non_adm_client.list_hypervisors)95 @test.attr(type=['negative'])96 @test.idempotent_id('dc02db05-e801-4c5f-bc8e-d915290ab345')97 def test_get_hypervisor_list_details_with_non_admin_user(self):98 # List of hypervisor details and available services with non admin user99 self.assertRaises(100 lib_exc.Forbidden,101 self.non_adm_client.list_hypervisors, detail=True)102 @test.attr(type=['negative'])103 @test.idempotent_id('19a45cc1-1000-4055-b6d2-28e8b2ec4faa')104 def test_search_nonexistent_hypervisor(self):105 nonexistent_hypervisor_name = data_utils.rand_name('test_hypervisor')106 self.assertRaises(107 lib_exc.NotFound,108 self.client.search_hypervisor,109 nonexistent_hypervisor_name)110 @test.attr(type=['negative'])111 @test.idempotent_id('5b6a6c79-5dc1-4fa5-9c58-9c8085948e74')112 def test_search_hypervisor_with_non_admin_user(self):113 hypers = self._list_hypervisors()114 self.assertTrue(len(hypers) > 0)115 self.assertRaises(116 lib_exc.Forbidden,117 self.non_adm_client.search_hypervisor,...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!