def test_create_cpu_mem_values(self):
     """
         check custom cpu/memmory with error in task
     """
     fake_ctx = self.generate_node_context(
         properties={
             'management_network': '_management_network',
             'vcloud_config': {
                 'vdc': 'vdc_name'
             },
             'server': {
                 'template': 'ubuntu',
                 'catalog': 'public',
                 'hardware': {
                     'cpu': 1,
                     'memory': 512
                 }
             }
         },
         relation_node_properties={
             "not_test": "not_test"
         }
     )
     fake_client = self.generate_client()
     self.run_with_statuses(
         fake_client, fake_ctx,
         vcloud_plugin_common.TASK_STATUS_SUCCESS,
         vcloud_plugin_common.TASK_STATUS_SUCCESS,
         vcloud_plugin_common.TASK_STATUS_SUCCESS,
         vcloud_plugin_common.TASK_STATUS_SUCCESS
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         # can't customize memory
         with self.assertRaises(cfy_exc.NonRecoverableError):
             server.configure(ctx=fake_ctx)
         fake_client._vapp.modify_vm_memory.assert_called_with(
             'test', 512
         )
         fake_client._vapp.modify_vm_memory = mock.MagicMock(
             return_value=self.generate_task(
                 vcloud_plugin_common.TASK_STATUS_SUCCESS
             )
         )
         # can't customize cpu
         with self.assertRaises(cfy_exc.NonRecoverableError):
             server.configure(ctx=fake_ctx)
         fake_client._vapp.modify_vm_cpu.assert_called_with(
             'test', 1
         )
         fake_client._vapp.modify_vm_cpu = mock.MagicMock(
             return_value=self.generate_task(
                 vcloud_plugin_common.TASK_STATUS_SUCCESS
             )
         )
         # everything fine
         server.create(ctx=fake_ctx)
 def test_server_create_delete(self):
     server.create()
     server.configure()
     vdc = self.vca_client.get_vdc(self.vcloud_config['org'])
     vapp = self.vca_client.get_vapp(
         vdc, self.ctx.node.properties['server']['name'])
     self.assertFalse(vapp is None)
     self.assertFalse(server._vapp_is_on(vapp))
     self.check_hardware(vapp)
     server.delete()
     vapp = self.vca_client.get_vapp(
         vdc, self.ctx.node.properties['server']['name'])
     self.assertTrue(vapp is None)
 def test_create_customization(self):
     """
         test customization - task None
     """
     fake_ctx = self.generate_context_for_customization()
     fake_client = self.generate_client()
     self.run_with_statuses(fake_client, fake_ctx,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS)
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         with self.assertRaises(cfy_exc.NonRecoverableError):
             server.configure(ctx=fake_ctx)
 def test_server_create_delete(self):
     server.create()
     server.configure()
     vdc = self.vca_client.get_vdc(self.vcloud_config['org'])
     vapp = self.vca_client.get_vapp(
         vdc,
         self.ctx.node.properties['server']['name'])
     self.assertFalse(vapp is None)
     self.assertFalse(server._vapp_is_on(vapp))
     self.check_hardware(vapp)
     server.delete()
     vapp = self.vca_client.get_vapp(
         vdc,
         self.ctx.node.properties['server']['name'])
     self.assertTrue(vapp is None)
 def test_create_customization_customized(self):
     """
         test customization - success customization
     """
     fake_ctx = self.generate_context_for_customization()
     fake_client = self.generate_client()
     fake_client._vapp.customize_on_next_poweron = mock.MagicMock(
         return_value=True)
     self.run_with_statuses(fake_client, fake_ctx,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS)
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         server.configure(ctx=fake_ctx)
 def test_create_customization(self):
     """
         test customization - task None
     """
     fake_ctx = self.generate_context_for_customization()
     fake_client = self.generate_client()
     self.run_with_statuses(
         fake_client, fake_ctx,
         vcloud_plugin_common.TASK_STATUS_SUCCESS,
         vcloud_plugin_common.TASK_STATUS_SUCCESS,
         vcloud_plugin_common.TASK_STATUS_SUCCESS
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         with self.assertRaises(cfy_exc.NonRecoverableError):
             server.configure(ctx=fake_ctx)
 def test_create_cpu_mem_values(self):
     """
         check custom cpu/memmory with error in task
     """
     fake_ctx = self.generate_node_context(
         properties={
             'management_network': '_management_network',
             'vcloud_config': {
                 'vdc': 'vdc_name'
             },
             'server': {
                 'template': 'ubuntu',
                 'catalog': 'public',
                 'hardware': {
                     'cpu': 1,
                     'memory': 512
                 }
             }
         },
         relation_node_properties={"not_test": "not_test"})
     fake_client = self.generate_client()
     self.run_with_statuses(fake_client, fake_ctx,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS,
                            vcloud_plugin_common.TASK_STATUS_SUCCESS)
     with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                     mock.MagicMock(return_value=fake_client)):
         # can't customize memory
         with self.assertRaises(cfy_exc.NonRecoverableError):
             server.configure(ctx=fake_ctx)
         fake_client._vapp.modify_vm_memory.assert_called_with('test', 512)
         fake_client._vapp.modify_vm_memory = mock.MagicMock(
             return_value=self.generate_task(
                 vcloud_plugin_common.TASK_STATUS_SUCCESS))
         # can't customize cpu
         with self.assertRaises(cfy_exc.NonRecoverableError):
             server.configure(ctx=fake_ctx)
         fake_client._vapp.modify_vm_cpu.assert_called_with('test', 1)
         fake_client._vapp.modify_vm_cpu = mock.MagicMock(
             return_value=self.generate_task(
                 vcloud_plugin_common.TASK_STATUS_SUCCESS))
         # everything fine
         server.create(ctx=fake_ctx)
 def test_create_customization_customized(self):
     """
         test customization - success customization
     """
     fake_ctx = self.generate_context_for_customization()
     fake_client = self.generate_client()
     fake_client._vapp.customize_on_next_poweron = mock.MagicMock(
         return_value=True
     )
     self.run_with_statuses(
         fake_client, fake_ctx,
         vcloud_plugin_common.TASK_STATUS_SUCCESS,
         vcloud_plugin_common.TASK_STATUS_SUCCESS,
         vcloud_plugin_common.TASK_STATUS_SUCCESS,
         vcloud_plugin_common.TASK_STATUS_SUCCESS
     )
     with mock.patch(
         'vcloud_plugin_common.VcloudAirClient.get',
         mock.MagicMock(return_value=fake_client)
     ):
         server.configure(ctx=fake_ctx)