How to use not_found_error method in localstack

Best Python code snippet using localstack_python

test_create_computer_system.py

Source:test_create_computer_system.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Copyright (2018) Hewlett Packard Enterprise Development LP3#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.15# Python libs16import copy17import json18# 3rd party libs19from unittest import mock20from unittest.mock import call21from flask_api import status22from hpOneView.exceptions import HPOneViewException23from hpOneView.resources.storage.storage_pools import StoragePools24from hpOneView.resources.servers.server_hardware import ServerHardware25from hpOneView.resources.servers.server_profile_templates import ServerProfileTemplate26from hpOneView.resources.storage.volumes import Volumes27from hpOneView.resources.activity.tasks import Tasks28# Module libs29from oneview_redfish_toolkit.api.errors import OneViewRedfishException30from oneview_redfish_toolkit.blueprints import computer_system31from oneview_redfish_toolkit.services import computer_system_service32from oneview_redfish_toolkit.tests.base_flask_test import BaseFlaskTest33class TestCreateComputerSystem(BaseFlaskTest):34 """Tests for Create a ComputerSystem blueprint endpoint"""35 @classmethod36 def setUpClass(self):37 super(TestCreateComputerSystem, self).setUpClass()38 self.app.register_blueprint(computer_system.computer_system)39 self.not_found_error = HPOneViewException({40 'errorCode': 'RESOURCE_NOT_FOUND',41 'message': 'resource not found',42 })43 with open(44 'oneview_redfish_toolkit/mockups/oneview/ServerProfile.json'45 ) as f:46 self.server_profile = json.load(f)47 #profile_obj = ServerProfiles(self.oneview_client, self.server_profile)48 with open(49 'oneview_redfish_toolkit/mockups/oneview/ServerHardware.json'50 ) as f:51 self.server_hardware = json.load(f)52 self.server_hardware['serverProfileUri'] = None53 with open(54 'oneview_redfish_toolkit/mockups/redfish/'55 'PostToComposeSystem.json'56 ) as f:57 self.data_to_create_system = json.load(f)58 self.data_to_create_system["Links"]["ResourceBlocks"].append(59 {60 "@odata.id": "/redfish/v1/CompositionService/"61 "ResourceBlocks/B526F59E-9BC7-467F-9205-A9F4015CE296"62 }63 )64 with open(65 'oneview_redfish_toolkit/mockups/oneview/'66 'ServerProfileTemplate.json'67 ) as f:68 server_profile_template = json.load(f)69 self.server_profile_template = copy.deepcopy(70 server_profile_template)71 self.server_profile_template["connectionSettings"][72 "connections"].append({73 "portId": "Mezz 3:1-b",74 "id": 2,75 "requestedVFs": "0",76 "functionType": "FibreChannel",77 "name": "fcnw",78 "boot": {79 "priority": "NotBootable",80 },81 "networkUri": "/rest/fc-networks/nw_id"82 })83 with open(84 'oneview_redfish_toolkit/mockups/oneview/'85 'Drives.json'86 ) as f:87 self.drives = json.load(f)88 with open(89 'oneview_redfish_toolkit/mockups/oneview/'90 'Volumes.json'91 ) as f:92 volumes = json.load(f)93 self.volume = volumes[0]94 self.sh_id = "30303437-3034-4D32-3230-313133364752"95 self.spt_id = "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0"96 self.drive1_id = "e11dd3e0-78cd-47e8-bacb-9813f4bb58a8"97 self.drive2_id = "53bd734f-19fe-42fe-a8ef-3f1a83b4e5c1"98 self.volume_id = "B526F59E-9BC7-467F-9205-A9F4015CE296"99 self.common_calls_to_assert_hardware = [100 call(self.sh_id),101 call(self.spt_id),102 call(self.drive1_id),103 call(self.drive2_id),104 call(self.volume_id)105 ]106 self.common_calls_to_assert_spt = [107 call(self.sh_id),108 call(self.spt_id),109 call(self.drive1_id),110 call(self.drive2_id),111 call(self.volume_id),112 call(self.spt_id)113 ]114 self.common_calls_to_assert_drives = [115 call('/rest/drives/' + self.sh_id),116 call('/rest/drives/' + self.spt_id),117 call('/rest/drives/' + self.drive1_id),118 call('/rest/drives/' + self.drive2_id),119 call('/rest/drives/' + self.volume_id)120 ]121 self.common_calls_to_assert_volumes = [122 call(self.sh_id),123 call(self.spt_id),124 call(self.drive1_id),125 call(self.drive2_id),126 call(self.volume_id),127 call(self.spt_id)128 ]129 self.fc_connection = {130 "portId": "Mezz 3:1-b",131 "id": 2,132 "requestedVFs": "0",133 "functionType": "FibreChannel",134 "name": "fcnw",135 "boot": {136 "priority": "NotBootable",137 },138 "networkUri": "/rest/fc-networks/nw_id"139 }140 self.san_storage = {141 "hostOSType": "VMware (ESXi)",142 "manageSanStorage": True,143 "volumeAttachments": [144 {145 "lunType": "Auto",146 "volumeUri": "/rest/storage-volumes/" +147 "B526F59E-9BC7-467F-9205-A9F4015CE296",148 "volumeStorageSystemUri": "/rest/storage-systems/"149 "TXQ1000307",150 "storagePaths": [151 {152 "targetSelector": "Auto",153 "isEnabled": True,154 "connectionId": 2,155 "targets": [156 ]157 }158 ]159 }160 ]161 }162 def run_common_mock_to_server_hardware(self):163 ov_client = self.oneview_client164 serverhw_obj = ServerHardware(165 self.oneview_client, self.server_hardware)166 ov_client.server_hardware.get_by_id.side_effect = [167 serverhw_obj,168 self.not_found_error,169 self.not_found_error,170 self.not_found_error,171 self.not_found_error,172 serverhw_obj, # for multiple oneview (power update status)173 serverhw_obj # for multiple oneview (create profile)174 ]175 #power_state.return_value = None176 def run_common_mock_to_server_profile_template(self):177 template_obj = ServerProfileTemplate(178 self.oneview_client, self.server_profile_template)179 self.oneview_client.server_profile_templates.get_by_id.side_effect = [180 self.not_found_error,181 template_obj,182 self.not_found_error,183 self.not_found_error,184 self.not_found_error,185 template_obj,186 ]187 def run_common_mock_to_drives(self):188 self.oneview_client.index_resources.get.side_effect = [189 self.not_found_error,190 self.not_found_error,191 self.drives[0],192 self.drives[1],193 self.not_found_error,194 ]195 def run_common_mock_to_volumes(self):196 volume_obj = Volumes(self.oneview_client, self.volume)197 self.oneview_client.volumes.get_by_id.side_effect = [198 self.not_found_error,199 self.not_found_error,200 self.not_found_error,201 self.not_found_error,202 volume_obj,203 self.not_found_error,204 ]205 def assert_common_calls(self):206 self.oneview_client.server_hardware.get_by_id.assert_has_calls(207 self.common_calls_to_assert_hardware)208 self.oneview_client.server_profile_templates.get_by_id.assert_has_calls(209 self.common_calls_to_assert_spt)210 self.oneview_client.index_resources.get.assert_has_calls(211 self.common_calls_to_assert_drives)212 @mock.patch.object(ServerHardware, 'update_power_state')213 @mock.patch.object(computer_system_service, 'time')214 def test_create_system(self, time_mock, power_state):215 """Tests create a redfish System with Network, Storage and Server"""216 with open(217 'oneview_redfish_toolkit/mockups/oneview/'218 'ServerProfileBuiltFromTemplateToCreateASystem.json'219 ) as f:220 expected_server_profile_built = json.load(f)221 expected_server_profile_built["sanStorage"] = self.san_storage222 expected_server_profile_built["connectionSettings"][223 "connections"].append(self.fc_connection)224 task_without_resource_uri = {225 "associatedResource": {226 "resourceUri": None227 },228 "uri": "/rest/tasks/123456"229 }230 task_with_resource_uri = {231 "associatedResource": {232 "resourceUri": self.server_profile["uri"]233 },234 "uri": "/rest/tasks/123456"235 }236 self.run_common_mock_to_server_hardware()237 power_state.return_value = None238 self.run_common_mock_to_server_profile_template()239 self.run_common_mock_to_drives()240 self.run_common_mock_to_volumes()241 storage_pool_obj = StoragePools(self.oneview_client, {242 "storageSystemUri": "/rest/storage-systems/TXQ1000307"243 })244 self.oneview_client.storage_pools.get_by_uri.return_value = storage_pool_obj245 # The connection.post return for /rest/server-profiles is a tuple246 self.oneview_client.connection.post.return_value = \247 (task_without_resource_uri, None)248 # The task will be requested 3 times in this case,249 # simulating the checking of resource uri250 task_without_resource_uri_obj = Tasks(251 self.oneview_client, task_without_resource_uri)252 task_with_resource_uri_obj = Tasks(253 self.oneview_client, task_with_resource_uri)254 self.oneview_client.tasks.get_by_uri.side_effect = [255 task_without_resource_uri_obj,256 task_without_resource_uri_obj,257 task_with_resource_uri_obj258 ]259 response = self.client.post(260 "/redfish/v1/Systems",261 data=json.dumps(self.data_to_create_system),262 content_type='application/json')263 self.assertEqual(status.HTTP_201_CREATED, response.status_code)264 self.assertEqual("application/json", response.mimetype)265 self.assertIn(266 "/redfish/v1/Systems/" + self.server_profile["uuid"],267 response.headers["Location"]268 )269 self.oneview_client.server_hardware.get_by_id.assert_has_calls(270 self.common_calls_to_assert_hardware)271 self.oneview_client.server_profile_templates.get_by_id.assert_has_calls(272 self.common_calls_to_assert_spt)273 self.oneview_client.index_resources.get.assert_has_calls(274 self.common_calls_to_assert_drives)275 self.oneview_client.server_profiles.create.assert_not_called()276 power_state \277 .assert_called_with({278 'powerControl': 'PressAndHold', 'powerState': 'Off'279 })280 self.oneview_client.tasks.get_by_uri.assert_called_with(281 task_without_resource_uri["uri"])282 # self.oneview_client.connection.post.assert_called_once_with(283 # '/rest/server-profiles', expected_server_profile_built284 # )285 self.assertEqual(self.oneview_client.tasks.get_by_uri.call_count, 3)286 time_mock.sleep.assert_called_with(3)287 def test_create_when_server_hardware_already_belongs_to_system(self,):288 """Tests create when server profile already applied to the server"""289 sh_with_profile_uri = copy.deepcopy(self.server_hardware)290 sh_with_profile_uri["serverProfileUri"] = "/server-profiles/uuid_1"291 self.oneview_client.server_hardware.get_by_id.side_effect = [292 sh_with_profile_uri,293 self.not_found_error,294 self.not_found_error,295 self.not_found_error,296 sh_with_profile_uri,297 sh_with_profile_uri298 ]299 self.run_common_mock_to_server_profile_template()300 self.run_common_mock_to_drives()301 response = self.client.post(302 "/redfish/v1/Systems",303 data=json.dumps(self.data_to_create_system),304 content_type="application/json")305 result = json.loads(response.data.decode("utf-8"))306 self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)307 self.assertEqual("application/json", response.mimetype)308 self.assertIn("Computer System Resource Block already belongs to a "309 "Composed System with ID uuid_1", str(result))310 self.oneview_client.connection.post.assert_not_called()311 @mock.patch.object(ServerHardware, 'update_power_state')312 @mock.patch.object(computer_system_service, 'config')313 def test_create_when_power_off_on_compose_is_not_configured(self,314 config_mock, power_state):315 """Tests create when power_off is blank, should below a normal flow"""316 with open(317 'oneview_redfish_toolkit/mockups/oneview/'318 'ServerProfileBuiltFromTemplateToCreateASystem.json'319 ) as f:320 expected_server_profile_built = json.load(f)321 expected_server_profile_built["sanStorage"] = self.san_storage322 expected_server_profile_built["connectionSettings"][323 "connections"].append(self.fc_connection)324 self.run_common_mock_to_server_hardware()325 self.run_common_mock_to_server_profile_template()326 self.run_common_mock_to_drives()327 self.run_common_mock_to_volumes()328 storage_pool_obj = StoragePools(self.oneview_client, {329 "storageSystemUri": "/rest/storage-systems/TXQ1000307"330 }331 )332 self.oneview_client.storage_pools.get_by_uri.return_value = storage_pool_obj333 config_mock.get_composition_settings.return_value = {334 'PowerOffServerOnCompose': ''335 }336 task_with_resource_uri = {337 "associatedResource": {338 "resourceUri": self.server_profile["uri"]339 },340 "uri": "/rest/tasks/123456"341 }342 self.oneview_client.connection.post.return_value = \343 (task_with_resource_uri, None)344 response = self.client.post(345 "/redfish/v1/Systems",346 data=json.dumps(self.data_to_create_system),347 content_type="application/json")348 self.assertEqual(status.HTTP_201_CREATED, response.status_code)349 self.assertEqual("application/json", response.mimetype)350 power_state.update_power_state \351 .assert_not_called()352 # self.oneview_client.connection.post.assert_called_once_with(353 # '/rest/server-profiles', expected_server_profile_built354 # )355 @mock.patch.object(ServerHardware, 'update_power_state')356 @mock.patch.object(computer_system_service, 'config')357 def test_create_when_power_off_on_compose_has_wrong_configuration(358 self, config_mock, power_state):359 """Tests create when power_off is blank, should below a normal flow"""360 self.run_common_mock_to_server_hardware()361 self.run_common_mock_to_server_profile_template()362 self.run_common_mock_to_drives()363 config_mock.get_composition_settings.return_value = {364 'PowerOffServerOnCompose': 'ForceOffff'365 }366 try:367 response = self.client.post(368 "/redfish/v1/Systems",369 data=json.dumps(self.data_to_create_system),370 content_type="application/json")371 result = json.loads(response.data.decode("utf-8"))372 except OneViewRedfishException:373 self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)374 self.assertIn('There is no mapping for ForceOffff on the OneView',375 str(result))376 power_state.update_power_state \377 .assert_not_called()378 self.oneview_client.connection.post.assert_not_called()379 @mock.patch.object(ServerHardware, 'update_power_state')380 @mock.patch.object(computer_system_service, 'time')381 def test_create_system_without_description(self, time_mock, power_state):382 """Tests create a redfish System with Network, Storage and Server"""383 with open(384 'oneview_redfish_toolkit/mockups/oneview/'385 'ServerProfileBuiltFromTemplateToCreateASystem.json'386 ) as f:387 expected_server_profile_built = json.load(f)388 task_without_resource_uri = {389 "associatedResource": {390 "resourceUri": None391 },392 "uri": "/rest/tasks/123456"393 }394 task_with_resource_uri = {395 "associatedResource": {396 "resourceUri": self.server_profile["uri"]397 },398 "uri": "/rest/tasks/123456"399 }400 expected_server_profile_built["sanStorage"] = self.san_storage401 expected_server_profile_built["connectionSettings"][402 "connections"].append(self.fc_connection)403 data_to_create_without_desc = copy.deepcopy(self.data_to_create_system)404 del expected_server_profile_built['description']405 data_to_create_without_desc['Description'] = ''406 self.run_common_mock_to_server_hardware()407 power_state.return_value = None408 self.run_common_mock_to_server_profile_template()409 self.run_common_mock_to_drives()410 self.run_common_mock_to_volumes()411 storage_prool_obj = StoragePools(self.oneview_client, {412 "storageSystemUri": "/rest/storage-systems/TXQ1000307"413 })414 self.oneview_client.storage_pools.get.return_value = storage_prool_obj415 # The connection.post return for /rest/server-profiles is a tuple416 self.oneview_client.connection.post.return_value = \417 (task_without_resource_uri, None)418 # The task will be requested 3 times in this case,419 # simulating the checking of resource uri420 task_without_resource_uri_obj = Tasks(421 self.oneview_client, task_without_resource_uri)422 task_with_resource_uri_obj = Tasks(423 self.oneview_client, task_with_resource_uri)424 self.oneview_client.tasks.get_by_uri.side_effect = [425 task_without_resource_uri_obj,426 task_without_resource_uri_obj,427 task_with_resource_uri_obj428 ]429 response = self.client.post(430 "/redfish/v1/Systems",431 data=json.dumps(data_to_create_without_desc),432 content_type='application/json')433 self.assertEqual(status.HTTP_201_CREATED, response.status_code)434 self.assertEqual("application/json", response.mimetype)435 self.assertIn(436 "/redfish/v1/Systems/" + self.server_profile["uuid"],437 response.headers["Location"]438 )439 self.oneview_client.server_hardware.get_by_id.assert_has_calls(440 self.common_calls_to_assert_hardware)441 self.oneview_client.server_profile_templates.get_by_id.assert_has_calls(442 self.common_calls_to_assert_spt)443 self.oneview_client.index_resources.get.assert_has_calls(444 self.common_calls_to_assert_drives)445 self.oneview_client.server_profiles.create.assert_not_called()446 self.oneview_client.tasks.get_by_uri.assert_called_with(447 task_without_resource_uri["uri"])448 # self.oneview_client.connection.post.assert_called_once_with(449 # '/rest/server-profiles', expected_server_profile_built450 # )451 self.assertEqual(self.oneview_client.tasks.get_by_uri.call_count, 3)452 time_mock.sleep.assert_called_with(3)453 def test_create_system_when_request_content_is_wrong(self):454 """Tests trying create a redfish System without Links"""455 data_to_send = {456 "Name": "Composed System Without Links"457 }458 response = self.client.post("/redfish/v1/Systems",459 data=json.dumps(data_to_send),460 content_type='application/json')461 self.assertEqual(462 status.HTTP_400_BAD_REQUEST, response.status_code)463 self.assertEqual("application/json", response.mimetype)464 self.oneview_client.server_hardware.get_by_id.assert_not_called()465 self.oneview_client.server_profile_templates.get_by_id.assert_not_called()466 self.oneview_client.index_resources.get.assert_not_called()467 self.oneview_client.connection.post.assert_not_called()468 def test_create_system_when_request_content_has_not_compute(self):469 """Tests trying create a redfish System without Compute Resource"""470 self.oneview_client.server_hardware.get_by_id.side_effect = [471 self.not_found_error,472 self.not_found_error,473 self.not_found_error,474 self.not_found_error,475 self.not_found_error476 ]477 response = self.client.post(478 "/redfish/v1/Systems/",479 data=json.dumps(self.data_to_create_system),480 content_type='application/json')481 self.assertEqual(482 status.HTTP_400_BAD_REQUEST, response.status_code)483 self.assertIn(484 "Should have a Computer System Resource Block",485 response.data.decode()486 )487 self.assertEqual("application/json", response.mimetype)488 self.oneview_client.server_hardware.get_by_id.assert_has_calls(489 self.common_calls_to_assert_hardware)490 self.oneview_client.server_profile_templates.get_by_id.assert_not_called()491 self.oneview_client.index_resources.get.assert_not_called()492 self.oneview_client.connection.post.assert_not_called()493 def test_create_system_when_request_content_has_not_network(self):494 """Tests trying create a redfish System without Network Resource"""495 self.oneview_client.server_hardware.get_by_id.side_effect = [496 self.server_hardware,497 self.not_found_error,498 self.not_found_error,499 self.not_found_error,500 self.not_found_error501 ]502 self.oneview_client.server_profile_templates.get_by_id.side_effect = [503 self.not_found_error,504 self.not_found_error,505 self.not_found_error,506 self.not_found_error,507 self.not_found_error508 ]509 response = self.client.post(510 "/redfish/v1/Systems/",511 data=json.dumps(self.data_to_create_system),512 content_type='application/json')513 self.assertEqual(514 status.HTTP_400_BAD_REQUEST, response.status_code)515 self.assertIn(516 "Should have a valid Network Resource Block",517 response.data.decode()518 )519 self.assertEqual("application/json", response.mimetype)520 self.oneview_client.server_hardware.get_by_id.assert_has_calls(521 self.common_calls_to_assert_hardware)522 self.oneview_client.server_profile_templates.get_by_id.assert_has_calls(523 [524 call(self.sh_id),525 call(self.spt_id),526 call(self.drive1_id),527 call(self.drive2_id)528 ])529 self.oneview_client.index_resources.get.assert_not_called()530 self.oneview_client.connection.post.assert_not_called()531 def test_create_system_when_request_content_has_not_a_valid_network(532 self):533 """Tests trying create a redfish System with a invalid Network"""534 self.oneview_client.server_hardware.get_by_id.side_effect = [535 self.server_hardware,536 self.not_found_error,537 self.not_found_error,538 self.not_found_error,539 self.not_found_error540 ]541 self.oneview_client.server_profile_templates.get_by_id.side_effect = [542 self.not_found_error,543 self.server_profile_template,544 self.not_found_error,545 self.not_found_error,546 self.not_found_error547 ]548 data_to_send = copy.copy(self.data_to_create_system)549 # wrong SPT id550 data_to_send["Id"] = "75871d70-789e-4cf9-8bc8-6f4d73193578"551 response = self.client.post(552 "/redfish/v1/Systems/",553 data=json.dumps(data_to_send),554 content_type='application/json')555 self.assertEqual(556 status.HTTP_400_BAD_REQUEST, response.status_code)557 self.assertIn(558 "Should have a valid Network Resource Block",559 response.data.decode()560 )561 self.assertEqual("application/json", response.mimetype)562 self.oneview_client.server_hardware.get_by_id.assert_has_calls(563 self.common_calls_to_assert_hardware)564 self.oneview_client.server_profile_templates.get_by_id.assert_has_calls(565 [566 call(self.sh_id),567 call(self.spt_id),568 call(self.drive1_id),569 call(self.drive2_id)570 ])571 self.oneview_client.index_resources.get.assert_not_called()572 self.oneview_client.connection.post.assert_not_called()573 @mock.patch.object(ServerHardware, 'update_power_state')574 @mock.patch.object(computer_system_service, 'time')575 def test_create_system_when_request_content_has_not_storage(self, _, power_state):576 """Tests create a redfish System without Storage.577 This test should works well.578 This case is when we are creating a System without Storage579 Resource Blocks, but the Server Profile Template related has a580 local storage controller configured properly581 """582 with open(583 'oneview_redfish_toolkit/mockups/redfish/'584 'PostToComposeSystemWithoutStorage.json'585 ) as f:586 data_to_send = json.load(f)587 """588 with open(589 'oneview_redfish_toolkit/mockups/oneview/'590 'ServerProfileBuiltFromZoneWithoutStorageToCreateASystem.json'591 ) as f:592 expected_server_profile_built = json.load(f)593 """594 with open(595 'oneview_redfish_toolkit/mockups/oneview/'596 'ServerProfileTemplates.json'597 ) as f:598 list_spt = json.load(f)599 spt = list_spt[1] # without local storage controller configured600 spt_id = spt["uri"].split("/")[-1]601 task = {602 "associatedResource": {603 "resourceUri": self.server_profile["uri"]604 },605 "uri": "/rest/tasks/123456"606 }607 serverhw_obj = ServerHardware(608 self.oneview_client, self.server_hardware)609 self.oneview_client.server_hardware.get_by_id.side_effect = [610 serverhw_obj,611 self.not_found_error,612 serverhw_obj, # for multiple oneview (power update status)613 serverhw_obj614 ]615 power_state.return_value = None616 template_obj = ServerProfileTemplate(self.oneview_client, spt)617 self.oneview_client.server_profile_templates.get_by_id.side_effect = [618 self.not_found_error,619 template_obj,620 template_obj,621 ]622 self.oneview_client.index_resources.get.side_effect = [623 self.not_found_error,624 self.not_found_error,625 ]626 self.run_common_mock_to_volumes()627 self.oneview_client.connection.post.return_value = (task, None)628 response = self.client.post(629 "/redfish/v1/Systems/",630 data=json.dumps(data_to_send),631 content_type='application/json')632 self.assertEqual(status.HTTP_201_CREATED, response.status_code)633 self.assertEqual("application/json", response.mimetype)634 self.assertIn(635 "/redfish/v1/Systems/" + self.server_profile["uuid"],636 response.headers["Location"]637 )638 self.oneview_client.server_hardware.get_by_id.assert_has_calls(639 [640 call(self.sh_id),641 call(spt_id),642 ])643 self.oneview_client.server_profile_templates.get_by_id.assert_has_calls(644 [645 call(self.sh_id),646 call(spt_id),647 call(spt_id)648 ])649 self.oneview_client.index_resources.get.assert_has_calls(650 [651 call('/rest/drives/' + self.sh_id),652 call('/rest/drives/' + spt_id),653 ])654 # self.oneview_client.connection.post.assert_called_with(655 # '/rest/server-profiles',656 # expected_server_profile_built)657 @mock.patch.object(ServerHardware, 'update_power_state')658 @mock.patch.object(computer_system_service, 'time')659 def test_create_system_when_has_not_storage_and_controller(self, _, power_state):660 """Tests create a System without Storage but with Storage Controller.661 This test should works well.662 This case is when we are creating a System without Storage663 Resource Blocks and the Server Profile Template related has not a664 local storage controller configured properly665 """666 task = {667 "associatedResource": {668 "resourceUri": self.server_profile["uri"]669 },670 "uri": "/rest/tasks/123456"671 }672 serverhw_obj = ServerHardware(673 self.oneview_client, self.server_hardware)674 self.oneview_client.server_hardware.get_by_id.side_effect = [675 serverhw_obj,676 self.not_found_error,677 self.not_found_error,678 self.not_found_error,679 self.not_found_error,680 serverhw_obj, # for multiple oneview (power update status)681 serverhw_obj # Get for multiple OneView support682 ]683 power_state.return_value = None684 template_without_controller = copy.deepcopy(685 self.server_profile_template)686 template_without_controller["localStorage"]["controllers"] = []687 template_obj = ServerProfileTemplate(688 self.oneview_client, template_without_controller)689 self.oneview_client.server_profile_templates.get_by_id.side_effect = [690 self.not_found_error,691 template_obj,692 self.not_found_error,693 self.not_found_error,694 self.not_found_error,695 template_obj696 ]697 self.oneview_client.index_resources.get.side_effect = [698 self.not_found_error,699 self.not_found_error,700 self.not_found_error,701 self.not_found_error,702 self.not_found_error,703 ]704 self.run_common_mock_to_volumes()705 storage_pools_obj = StoragePools(self.oneview_client, {706 "storageSystemUri": "/rest/storage-systems/TXQ1000307"707 })708 self.oneview_client.storage_pools.get.return_value = storage_pools_obj709 self.oneview_client.connection.post.return_value = (task, None)710 response = self.client.post(711 "/redfish/v1/Systems/",712 data=json.dumps(self.data_to_create_system),713 content_type='application/json')714 self.assertEqual(status.HTTP_201_CREATED, response.status_code)715 self.assertEqual("application/json", response.mimetype)716 # self.assertIn(717 # "/redfish/v1/Systems/" + self.server_profile["uuid"],718 # response.headers["Location"]719 # )720 self.assert_common_calls()721 def test_create_system_when_a_generic_exception_is_raised(self):722 """Tests create a redfish System when occurs a generic exception"""723 self.oneview_client.server_hardware.get_by_id.side_effect = Exception()724 response = self.client.post(725 "/redfish/v1/Systems/",726 data=json.dumps(self.data_to_create_system),727 content_type='application/json')728 self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR,729 response.status_code)730 self.assertEqual("application/json", response.mimetype)731 self.oneview_client.server_hardware.get_by_id.assert_called_with(732 self.sh_id)733 self.oneview_client.server_profile_templates.get_by_id.assert_not_called()734 self.oneview_client.index_resources.get.assert_not_called()735 @mock.patch.object(ServerHardware, 'update_power_state')736 @mock.patch.object(computer_system_service, 'time')737 def test_create_system_when_a_task_error_is_raised(self, _, power_state):738 """Tests create a System when the Oneview raises a task error.739 This test should return a http 403 with a error message.740 Some problems are server hardware is powered On and the drive used741 belongs to another enclosure.742 """743 task = {744 "associatedResource": {745 "resourceUri": None746 },747 "uri": "/rest/tasks/123456",748 "taskErrors": [749 {"message": "The server hardware 123 is powered on"}750 ]751 }752 self.run_common_mock_to_server_hardware()753 self.run_common_mock_to_server_profile_template()754 self.run_common_mock_to_drives()755 self.run_common_mock_to_volumes()756 self.oneview_client.connection.post.return_value = (task, object())757 response = self.client.post(758 "/redfish/v1/Systems/",759 data=json.dumps(self.data_to_create_system),760 content_type='application/json')761 self.assertEqual(762 status.HTTP_403_FORBIDDEN,763 response.status_code764 )765 self.assertEqual("application/json", response.mimetype)766 self.assertIn("The server hardware 123 is powered on",767 response.data.decode())768 self.assert_common_calls()769 @mock.patch.object(ServerHardware, 'update_power_state')770 @mock.patch.object(computer_system_service, 'time')771 def test_when_has_more_than_one_task_error(self, _, power_state):772 """Tests create a System when the Oneview raises two task errors.773 This test should return a http 403 with a error message.774 Some problems are server hardware is powered On and the drive used775 belongs to another enclosure.776 """777 task = {778 "associatedResource": {779 "resourceUri": None780 },781 "uri": "/rest/tasks/123456",782 "taskErrors": [783 {"message": "The server hardware 123 is powered on"},784 {"message": "The drive used belongs to another enclosure"}785 ]786 }787 self.run_common_mock_to_server_hardware()788 power_state.return_value = None789 self.run_common_mock_to_server_profile_template()790 self.run_common_mock_to_drives()791 self.run_common_mock_to_volumes()792 self.oneview_client.connection.post.return_value = (task, object())793 response = self.client.post(794 "/redfish/v1/Systems/",795 data=json.dumps(self.data_to_create_system),796 content_type='application/json')797 expected_error_msg = "The server hardware 123 is powered on\\n" \798 "The drive used belongs to another enclosure\\n"799 self.assertEqual(800 status.HTTP_403_FORBIDDEN,801 response.status_code802 )803 self.assertEqual("application/json", response.mimetype)804 self.assertIn(expected_error_msg, response.data.decode())805 self.assert_common_calls()806 def test_create_system_when_has_storage_but_not_valid_controller(self):807 """Tests when the Server Profile Template has not a valid storage controller.808 This test should return a http 403 with a error message.809 The case is: the server profile template associated with the810 request has not a valid local storage controller configured,811 but the request has storage resource blocks to compose the system812 """813 self.run_common_mock_to_server_hardware()814 template_without_controller = copy.deepcopy(815 self.server_profile_template)816 template_without_controller["localStorage"]["controllers"] = []817 spt_without_controller_obj = ServerProfileTemplate(818 self.oneview_client, template_without_controller)819 self.oneview_client.server_profile_templates.get_by_id.side_effect = [820 self.not_found_error,821 spt_without_controller_obj,822 self.not_found_error,823 self.not_found_error,824 spt_without_controller_obj825 ]826 self.run_common_mock_to_drives()827 try:828 response = self.client.post(829 "/redfish/v1/Systems/",830 data=json.dumps(self.data_to_create_system),831 content_type='application/json')832 except OneViewRedfishException:833 self.assertEqual(834 status.HTTP_403_FORBIDDEN,835 response.status_code836 )837 self.assertIn("The Server Profile Template should have a valid "838 "storage controller to use the Storage Resource "839 "Blocks passed",840 response.data.decode())...

Full Screen

Full Screen

check_consistency.py

Source:check_consistency.py Github

copy

Full Screen

1import os2import sys3path = "/Users/avankemp/Workspace/Triple-A/Experiments/G5K/Interval_7s/Renater20000Jobs_Cache20_40_60_seed777_7s/transient"4os.chdir(path)5for filename in os.listdir(os.getcwd()):6 if not filename.startswith('.'):7 if os.path.isdir(filename):8 print(filename)9 if filename.startswith("dht"):10 cmd = """ grep -r "Error 404" """ + filename + "/*"11 list_of_file_not_found = os.popen(cmd).read()12 list_of_file_not_found = list_of_file_not_found.split("\n")13 del list_of_file_not_found[-1]14 nbr_of_error = len(list_of_file_not_found)15 print("404 errors: "+ str(nbr_of_error))16 for not_found_error in list_of_file_not_found:17 cluster_name = not_found_error.split("/")[1].split("-")[0]18 job_id = not_found_error.split(":")[6]19 to_grep_msg = job_id + ":DEBUG:DHT:req_time"20 to_grep_cmd = """ grep "{}" {} """.format(to_grep_msg, not_found_error.split(":")[0])21 dht_req_node = os.popen(to_grep_cmd).read()22 error_location = dht_req_node.split(",")[3].split(".")[3].split("\n")[0]23 location = not_found_error.split(",")[1].split("=")[1].split(".")[3]24 file_hash = not_found_error.split(":")[8].split("=")[1].split(',')[0]25 log_to_check = not_found_error.replace(not_found_error.split('/')[1].split("-")[0]+"-"+not_found_error.split('/')[1].split("-")[1], cluster_name+"-"+error_location).split(":")[0]26 req_msg = job_id + ":DEFAULT:{'type': 'DHT', 'subtype': 'request', 'file_hash':"+file_hash27 del_msg = "DEFAULT:{'type': 'DHT', 'subtype': 'del', 'file_hash':"+file_hash28 cmd_req = """ grep -A 500 "{}" {} """.format(req_msg, log_to_check)29 cmd_req = cmd_req.replace("\\", "")30 req_found = os.popen(cmd_req).read()31 req_found = req_found.split("\n")32 del req_found[-1]33 found_del_msg = False34 for log_entry in req_found:35 if del_msg in log_entry:36 found_del_msg = True37 print(job_id+ " - Found the DEL msg right after")38 break39 if found_del_msg == False:40 sys.exit(job_id+ " - INCONSISTENCY - No del message... - ")41 elif filename.startswith("new"):42 cmd = """ grep -r "Error 404" """ + filename + "/*"43 list_of_file_not_found = os.popen(cmd).read()44 list_of_file_not_found = list_of_file_not_found.split("\n")45 del list_of_file_not_found[-1]46 nbr_of_error = len(list_of_file_not_found)47 print("404 errors: " + str(nbr_of_error))48 for not_found_error in list_of_file_not_found:49 log_to_check = not_found_error.split(":")[0]50 job_id = not_found_error.split(":")[6]51 file_hash = not_found_error.split(":")[8].split("=")[1].split(',')[0]52 cmd_grep = """ grep -A 2500 -B 2500 "{}" {} """.format(job_id+":Error 404", log_to_check)53 req_found = os.popen(cmd_grep).read()54 req_found = req_found.split("\n")55 del req_found[-1]56 found_del_msg = False57 del_msg = "DEFAULT:{'type': 'DELETE', 'file_hash':"+file_hash58 for log_entry in req_found:59 if del_msg in log_entry:60 found_del_msg = True61 print(job_id+ " - Found the DEL msg right after")62 break63 if found_del_msg == False:...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...14 except BaseException:15 print("home/error/try1")16 return render_template('index.html', form=form)17@app.errorhandler(400)18def not_found_error(error):19 pass20 # return render_template('Error/400.html'), 40021@app.errorhandler(401)22def not_found_error(error):23 pass24 # return render_template('Error/401.html'), 40125@app.errorhandler(404)26def not_found_error(error):27 return render_template('404/404.html'), 40428@app.errorhandler(500)29def not_found_error(error):30 pass31 # return render_template('Error/500.html'), 50032@app.errorhandler(502)33def not_found_error(error):34 pass35 # return render_template('Error/502.html'), 50236@app.errorhandler(503)37def not_found_error(error):38 pass39 # return render_template('Error/503.html'), 50340if __name__ == '__main__':41 port = int(os.environ.get("PORT", 5000))...

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