How to use create_flavor method in tempest

Best Python code snippet using tempest_python

test_flavor.py

Source:test_flavor.py Github

copy

Full Screen

...39 super(NovaFlavorTest, self).setUp()40 self.patchobject(novac.NovaClientPlugin, 'has_extension',41 return_value=True)42 self.ctx = utils.dummy_context()43 def create_flavor(self, with_name_id=False, is_public=True):44 if with_name_id:45 props = flavor_template['resources']['my_flavor']['properties']46 props['name'] = 'test_flavor'47 props['flavorid'] = '1234'48 if not is_public:49 props = flavor_template['resources']['my_flavor']['properties']50 props['is_public'] = False51 props['tenants'] = ["foo", "bar"]52 self.stack = stack.Stack(53 self.ctx, 'nova_flavor_test_stack',54 template.Template(flavor_template)55 )56 self.my_flavor = self.stack['my_flavor']57 nova = mock.MagicMock()58 self.novaclient = mock.MagicMock()59 self.my_flavor.client = nova60 nova.return_value = self.novaclient61 self.flavors = self.novaclient.flavors62 def test_flavor_handle_create_no_id_name(self):63 self.create_flavor()64 kwargs = {65 'vcpus': 2, 'disk': 20, 'swap': 2,66 'flavorid': 'auto', 'is_public': True,67 'rxtx_factor': 1.0, 'ram': 1024,68 'ephemeral': 0, 'name': 'm1.xxx'69 }70 self.patchobject(self.my_flavor, 'physical_resource_name',71 return_value='m1.xxx')72 value = mock.MagicMock()73 flavor_id = '927202df-1afb-497f-8368-9c2d2f26e5db'74 value.id = flavor_id75 value.is_public = True76 value.get_keys.return_value = {'k': 'v'}77 self.flavors.create.return_value = value78 self.flavors.get.return_value = value79 self.my_flavor.handle_create()80 self.flavors.create.assert_called_once_with(**kwargs)81 value.set_keys.assert_called_once_with({"foo": "bar"})82 self.assertEqual(flavor_id, self.my_flavor.resource_id)83 self.assertTrue(self.my_flavor.FnGetAtt('is_public'))84 self.assertEqual({'k': 'v'}, self.my_flavor.FnGetAtt('extra_specs'))85 def test_flavor_handle_create_with_id_name(self):86 self.create_flavor(with_name_id=True)87 kwargs = {88 'vcpus': 2, 'disk': 20, 'swap': 2,89 'flavorid': '1234', 'is_public': True,90 'rxtx_factor': 1.0, 'ram': 1024,91 'ephemeral': 0, 'name': 'test_flavor'92 }93 self.patchobject(self.my_flavor, 'physical_resource_name',94 return_value='m1.xxx')95 value = mock.MagicMock()96 flavor_id = '927202df-1afb-497f-8368-9c2d2f26e5db'97 value.id = flavor_id98 value.is_public = True99 self.flavors.create.return_value = value100 self.flavors.get.return_value = value101 self.my_flavor.handle_create()102 self.flavors.create.assert_called_once_with(**kwargs)103 value.set_keys.assert_called_once_with({"foo": "bar"})104 self.assertEqual(flavor_id, self.my_flavor.resource_id)105 self.assertTrue(self.my_flavor.FnGetAtt('is_public'))106 def test_private_flavor_handle_create(self):107 self.create_flavor(is_public=False)108 value = mock.MagicMock()109 flavor_id = '927202df-1afb-497f-8368-9c2d2f26e5db'110 value.id = flavor_id111 value.is_public = False112 self.flavors.create.return_value = value113 self.flavors.get.return_value = value114 self.my_flavor.handle_create()115 value.set_keys.assert_called_once_with({"foo": "bar"})116 self.assertEqual(flavor_id, self.my_flavor.resource_id)117 self.assertFalse(self.my_flavor.FnGetAtt('is_public'))118 client_test = self.my_flavor.client().flavor_access.add_tenant_access119 test_tenants = [mock.call(value, 'foo'), mock.call(value, 'bar')]120 self.assertEqual(test_tenants, client_test.call_args_list)121 def test_flavor_handle_update_keys(self):122 self.create_flavor()123 value = mock.MagicMock()124 self.flavors.get.return_value = value125 value.get_keys.return_value = {}126 new_keys = {"new_foo": "new_bar"}127 prop_diff = {'extra_specs': new_keys}128 self.my_flavor.handle_update(json_snippet=None,129 tmpl_diff=None, prop_diff=prop_diff)130 value.unset_keys.assert_called_once_with({})131 value.set_keys.assert_called_once_with(new_keys)132 def test_flavor_handle_update_add_tenants(self):133 self.create_flavor(is_public=False)134 value = mock.MagicMock()135 new_tenants = ["new_foo", "new_bar"]136 prop_diff = {'tenants': new_tenants}137 self.flavors.get.return_value = value138 self.my_flavor.handle_update(json_snippet=None,139 tmpl_diff=None, prop_diff=prop_diff)140 test_tenants_add = [mock.call(value, 'new_foo'),141 mock.call(value, 'new_bar')]142 test_add = self.my_flavor.client().flavor_access.add_tenant_access143 self.assertItemsEqual(test_tenants_add,144 test_add.call_args_list)145 def test_flavor_handle_update_remove_tenants(self):146 self.create_flavor(is_public=False)147 value = mock.MagicMock()148 new_tenants = []149 prop_diff = {'tenants': new_tenants}150 self.flavors.get.return_value = value151 itemFoo = mock.MagicMock()152 itemFoo.tenant_id = 'foo'153 itemBar = mock.MagicMock()154 itemBar.tenant_id = 'bar'155 self.my_flavor.client().flavor_access.list.return_value = [itemFoo,156 itemBar]157 self.my_flavor.handle_update(json_snippet=None,158 tmpl_diff=None, prop_diff=prop_diff)159 test_tenants_remove = [mock.call(value, 'foo'),160 mock.call(value, 'bar')]161 test_rem = self.my_flavor.client().flavor_access.remove_tenant_access162 self.assertItemsEqual(test_tenants_remove,163 test_rem.call_args_list)164 def test_flavor_show_resource(self):165 self.create_flavor()166 self.my_flavor.resource_id = 'flavor_test_id'167 self.my_flavor.client = mock.MagicMock()168 flavors = mock.MagicMock()169 flavor = mock.MagicMock()170 flavor.to_dict.return_value = {'flavor': 'info'}171 flavors.get.return_value = flavor172 self.my_flavor.client().flavors = flavors173 self.assertEqual({'flavor': 'info'}, self.my_flavor.FnGetAtt('show'))174 flavors.get.assert_called_once_with('flavor_test_id')175 def test_flavor_get_live_state(self):176 self.create_flavor()177 value = mock.MagicMock()178 value.get_keys.return_value = {'key': 'value'}179 value.to_dict.return_value = {'ram': 1024,180 'disk': 0,181 'vcpus': 1,182 'rxtx_factor': 1.0,183 'OS-FLV-EXT-DATA:ephemeral': 0,184 'os-flavor-access:is_public': True}185 self.flavors.get.return_value = value186 self.my_flavor.resource_id = '1234'187 reality = self.my_flavor.get_live_state(self.my_flavor.properties)...

Full Screen

Full Screen

test_win.py

Source:test_win.py Github

copy

Full Screen

1from mpi4py import MPI2import mpiunittest as unittest3try:4 from sys import getrefcount5except ImportError:6 class getrefcount(object):7 def __init__(self, arg):8 pass9 def __eq__(self, other):10 return True11 def __add__(self, other):12 return self13 def __sub__(self, other):14 return self15def memzero(m):16 n = len(m)17 if n == 0: return18 try:19 zero = b'\0'20 m[0] = zero21 except TypeError:22 zero = 023 m[0] = zero24 for i in range(n):25 m[i] = zero26class BaseTestWin(object):27 COMM = MPI.COMM_NULL28 INFO = MPI.INFO_NULL29 CREATE_FLAVOR = MPI.UNDEFINED30 def testGetAttr(self):31 base = MPI.Get_address(self.memory)32 size = len(self.memory)33 unit = 134 self.assertEqual(size, self.WIN.Get_attr(MPI.WIN_SIZE))35 self.assertEqual(unit, self.WIN.Get_attr(MPI.WIN_DISP_UNIT))36 self.assertEqual(base, self.WIN.Get_attr(MPI.WIN_BASE))37 def testMemory(self):38 memory = self.WIN.memory39 pointer = MPI.Get_address(memory)40 length = len(memory)41 base, size, dunit = self.WIN.attrs42 self.assertEqual(size, length)43 self.assertEqual(dunit, 1)44 self.assertEqual(base, pointer)45 def testAttributes(self):46 base, size, unit = self.WIN.attrs47 self.assertEqual(size, len(self.memory))48 self.assertEqual(unit, 1)49 self.assertEqual(base, MPI.Get_address(self.memory))50 def testGetGroup(self):51 cgroup = self.COMM.Get_group()52 wgroup = self.WIN.Get_group()53 grpcmp = MPI.Group.Compare(cgroup, wgroup)54 cgroup.Free()55 wgroup.Free()56 self.assertEqual(grpcmp, MPI.IDENT)57 def testGetSetInfo(self):58 #info = MPI.INFO_NULL59 #self.WIN.Set_info(info)60 info = MPI.Info.Create()61 self.WIN.Set_info(info)62 info.Free()63 info = self.WIN.Get_info()64 self.WIN.Set_info(info)65 info.Free()66 def testGetSetErrhandler(self):67 for ERRHANDLER in [MPI.ERRORS_ARE_FATAL, MPI.ERRORS_RETURN,68 MPI.ERRORS_ARE_FATAL, MPI.ERRORS_RETURN,]:69 errhdl_1 = self.WIN.Get_errhandler()70 self.assertNotEqual(errhdl_1, MPI.ERRHANDLER_NULL)71 self.WIN.Set_errhandler(ERRHANDLER)72 errhdl_2 = self.WIN.Get_errhandler()73 self.assertEqual(errhdl_2, ERRHANDLER)74 errhdl_2.Free()75 self.assertEqual(errhdl_2, MPI.ERRHANDLER_NULL)76 self.WIN.Set_errhandler(errhdl_1)77 errhdl_1.Free()78 self.assertEqual(errhdl_1, MPI.ERRHANDLER_NULL)79 def testGetSetName(self):80 try:81 name = self.WIN.Get_name()82 self.WIN.Set_name('mywin')83 self.assertEqual(self.WIN.Get_name(), 'mywin')84 self.WIN.Set_name(name)85 self.assertEqual(self.WIN.Get_name(), name)86 except NotImplementedError:87 pass88 def testCreateFlavor(self):89 if MPI.WIN_CREATE_FLAVOR == MPI.KEYVAL_INVALID: return90 flavors = (MPI.WIN_FLAVOR_CREATE,91 MPI.WIN_FLAVOR_ALLOCATE,92 MPI.WIN_FLAVOR_DYNAMIC,93 MPI.WIN_FLAVOR_SHARED,)94 flavor = self.WIN.Get_attr(MPI.WIN_CREATE_FLAVOR)95 self.assertTrue (flavor in flavors)96 self.assertEqual(flavor, self.WIN.flavor)97 self.assertEqual(flavor, self.CREATE_FLAVOR)98 def testMemoryModel(self):99 if MPI.WIN_MODEL == MPI.KEYVAL_INVALID: return100 models = (MPI.WIN_SEPARATE, MPI.WIN_UNIFIED)101 model = self.WIN.Get_attr(MPI.WIN_MODEL)102 self.assertTrue (model in models)103 self.assertEqual(model, self.WIN.model)104class BaseTestWinCreate(BaseTestWin):105 CREATE_FLAVOR = MPI.WIN_FLAVOR_CREATE106 def setUp(self):107 self.memory = MPI.Alloc_mem(10)108 memzero(self.memory)109 self.WIN = MPI.Win.Create(self.memory, 1, self.INFO, self.COMM)110 def tearDown(self):111 self.WIN.Free()112 MPI.Free_mem(self.memory)113class BaseTestWinAllocate(BaseTestWin):114 CREATE_FLAVOR = MPI.WIN_FLAVOR_ALLOCATE115 def setUp(self):116 self.WIN = MPI.Win.Allocate(10, 1, self.INFO, self.COMM)117 self.memory = self.WIN.memory118 memzero(self.memory)119 def tearDown(self):120 self.WIN.Free()121class BaseTestWinAllocateShared(BaseTestWin):122 CREATE_FLAVOR = MPI.WIN_FLAVOR_SHARED123 def setUp(self):124 self.WIN = MPI.Win.Allocate_shared(10, 1, self.INFO, self.COMM)125 self.memory = self.WIN.memory126 memzero(self.memory)127 def tearDown(self):128 self.WIN.Free()129 def testSharedQuery(self):130 memory = self.WIN.memory131 address = MPI.Get_address(memory)132 length = len(memory)133 memories = self.COMM.allgather((address, length))134 rank = self.COMM.Get_rank()135 size = self.COMM.Get_size()136 for i in range(size):137 mem, disp = self.WIN.Shared_query(rank)138 base = MPI.Get_address(mem)139 size = len(mem)140 if i == rank:141 self.assertEqual(base, memories[i][0])142 self.assertEqual(size, memories[i][1])143 self.assertEqual(disp, 1)144class BaseTestWinCreateDynamic(BaseTestWin):145 CREATE_FLAVOR = MPI.WIN_FLAVOR_DYNAMIC146 def setUp(self):147 self.WIN = MPI.Win.Create_dynamic(self.INFO, self.COMM)148 def tearDown(self):149 self.WIN.Free()150 def testGetAttr(self):151 base = self.WIN.Get_attr(MPI.WIN_BASE)152 size = self.WIN.Get_attr(MPI.WIN_SIZE)153 disp = self.WIN.Get_attr(MPI.WIN_DISP_UNIT)154 self.assertEqual(base, 0)155 self.assertEqual(size, 0)156 #self.assertEqual(disp, 1)157 def testMemory(self):158 self.assertTrue(self.WIN.memory is None)159 def testAttributes(self):160 pass161 def testAttachDetach(self):162 mem1 = MPI.Alloc_mem(8)163 mem2 = MPI.Alloc_mem(16)164 mem3 = MPI.Alloc_mem(32)165 for mem in (mem1, mem2, mem3):166 self.WIN.Attach(mem)167 self.testMemory()168 self.WIN.Detach(mem)169 for mem in (mem1, mem2, mem3):170 self.WIN.Attach(mem)171 self.testMemory()172 for mem in (mem1, mem2, mem3):173 self.WIN.Detach(mem)174 for mem in (mem1, mem2, mem3):175 self.WIN.Attach(mem)176 self.testMemory()177 for mem in (mem3, mem2, mem1):178 self.WIN.Detach(mem)179 MPI.Free_mem(mem1)180 MPI.Free_mem(mem2)181 MPI.Free_mem(mem3)182class TestWinCreateSelf(BaseTestWinCreate, unittest.TestCase):183 COMM = MPI.COMM_SELF184class TestWinCreateWorld(BaseTestWinCreate, unittest.TestCase):185 COMM = MPI.COMM_WORLD186class TestWinAllocateSelf(BaseTestWinAllocate, unittest.TestCase):187 COMM = MPI.COMM_SELF188class TestWinAllocateWorld(BaseTestWinAllocate, unittest.TestCase):189 COMM = MPI.COMM_WORLD190class TestWinAllocateSharedSelf(BaseTestWinAllocateShared, unittest.TestCase):191 COMM = MPI.COMM_SELF192class TestWinAllocateSharedWorld(BaseTestWinAllocateShared, unittest.TestCase):193 COMM = MPI.COMM_WORLD194class TestWinCreateDynamicSelf(BaseTestWinCreateDynamic, unittest.TestCase):195 COMM = MPI.COMM_SELF196class TestWinCreateDynamicWorld(BaseTestWinCreateDynamic, unittest.TestCase):197 COMM = MPI.COMM_WORLD198try:199 MPI.Win.Create(MPI.BOTTOM, 1, MPI.INFO_NULL, MPI.COMM_SELF).Free()200except NotImplementedError:201 del TestWinCreateSelf, TestWinCreateWorld202try:203 MPI.Win.Allocate(1, 1, MPI.INFO_NULL, MPI.COMM_SELF).Free()204except NotImplementedError:205 del TestWinAllocateSelf, TestWinAllocateWorld206try:207 MPI.Win.Allocate_shared(1, 1, MPI.INFO_NULL, MPI.COMM_SELF).Free()208except NotImplementedError:209 del TestWinAllocateSharedSelf, TestWinAllocateSharedWorld210try:211 MPI.Win.Create_dynamic(MPI.INFO_NULL, MPI.COMM_SELF).Free()212except NotImplementedError:213 del TestWinCreateDynamicSelf, TestWinCreateDynamicWorld214name, version = MPI.get_vendor()215if name == 'Open MPI':216 if version < (1,4,0):217 if MPI.Query_thread() > MPI.THREAD_SINGLE:218 del TestWinCreateWorld219 del TestWinAllocateWorld220if name == 'MPICH2':221 import sys222 if sys.platform.startswith('win'):223 del BaseTestWin.testAttributes224if __name__ == '__main__':...

Full Screen

Full Screen

createFlavour.py

Source:createFlavour.py Github

copy

Full Screen

...6username="admin",7password="manoj",8user_domain_id="default",9project_domain_id="default")10def create_flavor(conn):11 flavor_properties = {'name':'packtpub-flavor', 'disk':'1', 'ram':'2048', 'vcpus':'2'}12 conn.compute.create_flavor(**flavor_properties)...

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 tempest 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