From dc6aa93ea06d430cfa0358866755b380b56cdb78 Mon Sep 17 00:00:00 2001 From: micafer Date: Wed, 16 May 2018 10:13:03 +0200 Subject: [PATCH] Style changes --- IM/config.py | 2 ++ IM/db.py | 1 + IM/request.py | 1 + contextualization/ctxt_agent.py | 1 + contextualization/ctxt_agent_dist.py | 1 + im_service.py | 1 + scripts/db_1_4_to_1_5.py | 1 + scripts/delete_old_infs.py | 1 + test/functional/test_im.py | 1 + test/integration/QuickTestIM.py | 1 + test/integration/TestIM.py | 1 + test/integration/TestREST.py | 1 + test/integration/TestREST_JSON.py | 1 + test/loadtest/LoadTest.py | 1 + test/loadtest/LoadTestR.py | 1 + test/loadtest/LoadTestREST.py | 1 + test/loadtest/LoadTestRESTR.py | 1 + test/unit/REST.py | 1 + test/unit/ServiceRequests.py | 1 + test/unit/Tosca.py | 1 + test/unit/VMRC.py | 1 + test/unit/connectors/GCE.py | 1 + test/unit/connectors/OpenNebula.py | 1 + test/unit/db.py | 1 + test/unit/onetts.py | 1 + test/unit/openid.py | 1 + test/unit/recipe.py | 1 + test/unit/test_ansible.py | 1 + test/unit/test_ctxt_agent.py | 1 + test/unit/test_ctxt_agent_dist.py | 1 + test/unit/test_im_logic.py | 1 + test/unit/timedcall.py | 1 + test/unit/tts.py | 2 ++ test/unit/xmlobject.py | 1 + 34 files changed, 36 insertions(+) diff --git a/IM/config.py b/IM/config.py index 78654caf0..d47450d00 100644 --- a/IM/config.py +++ b/IM/config.py @@ -103,6 +103,7 @@ class Config: VM_NUM_USE_CTXT_DIST = 30 DELAY_BETWEEN_VM_RETRIES = 5 + config = ConfigParser() config.read([Config.IM_PATH + '/../im.cfg', Config.IM_PATH + '/../etc/im.cfg', '/etc/im/im.cfg']) @@ -128,6 +129,7 @@ class ConfigOpenNebula: IMAGE_UNAME = '' TTS_URL = 'https://localhost:8443' + if config.has_section("OpenNebula"): parse_options(config, 'OpenNebula', ConfigOpenNebula) diff --git a/IM/db.py b/IM/db.py index ac98b3142..dcb8a0113 100644 --- a/IM/db.py +++ b/IM/db.py @@ -227,6 +227,7 @@ def table_exists(self, table_name): else: return True + try: class IntegrityError(sqlite.IntegrityError): """ Class to return IntegrityError independently of the DB used""" diff --git a/IM/request.py b/IM/request.py index f6421b243..7bf4a507b 100644 --- a/IM/request.py +++ b/IM/request.py @@ -280,6 +280,7 @@ def serve_forever_in_thread(self): self.__thread.daemon = True self.__thread.start() + if Config.XMLRCP_SSL: class AsyncSSLXMLRPCServer(ThreadingMixIn, SSLSimpleXMLRPCServer): diff --git a/contextualization/ctxt_agent.py b/contextualization/ctxt_agent.py index 89de58edf..a8877d372 100644 --- a/contextualization/ctxt_agent.py +++ b/contextualization/ctxt_agent.py @@ -630,6 +630,7 @@ def run(general_conf_file, vm_conf_file): return res_data['OK'] + if __name__ == "__main__": parser = argparse.ArgumentParser(description='Contextualization Agent.') parser.add_argument('general', type=str, nargs=1) diff --git a/contextualization/ctxt_agent_dist.py b/contextualization/ctxt_agent_dist.py index b5635ea72..4ff3fe390 100755 --- a/contextualization/ctxt_agent_dist.py +++ b/contextualization/ctxt_agent_dist.py @@ -960,6 +960,7 @@ def run(general_conf_file, vm_conf_file, local): return res_data['OK'] + if __name__ == "__main__": parser = argparse.ArgumentParser(description='Contextualization Agent.') parser.add_argument('general', type=str, nargs=1) diff --git a/im_service.py b/im_service.py index c0ed75964..a64566e60 100755 --- a/im_service.py +++ b/im_service.py @@ -373,6 +373,7 @@ def signal_int_handler(signal, frame): """ im_stop() + if __name__ == "__main__": parser = argparse.ArgumentParser(description='IM service') parser.add_argument('--version', help='Show IM service version.', dest="version", diff --git a/scripts/db_1_4_to_1_5.py b/scripts/db_1_4_to_1_5.py index 5b2699486..e83588266 100644 --- a/scripts/db_1_4_to_1_5.py +++ b/scripts/db_1_4_to_1_5.py @@ -105,6 +105,7 @@ def complete_data(): vm.cloud_connector = None vm.inf = None + if __name__ == "__main__": if not Config.DATA_DB: sys.stderr.write("No DATA_DB defined in the im.cfg file!!") diff --git a/scripts/delete_old_infs.py b/scripts/delete_old_infs.py index 16e77d25b..268e1238f 100644 --- a/scripts/delete_old_infs.py +++ b/scripts/delete_old_infs.py @@ -36,6 +36,7 @@ def delete_data_from_db(db_url, date): sys.stderr.write("ERROR connecting with the database!.") sys.exit(-1) + if __name__ == "__main__": if not Config.DATA_DB: sys.stderr.write("No DATA_DB defined in the im.cfg file!!\n") diff --git a/test/functional/test_im.py b/test/functional/test_im.py index 4d35c32ec..11ee3ab34 100755 --- a/test/functional/test_im.py +++ b/test/functional/test_im.py @@ -182,5 +182,6 @@ def test_inf_lifecycle(self): IM.DestroyInfrastructure(infId, auth0) + if __name__ == "__main__": unittest.main() diff --git a/test/integration/QuickTestIM.py b/test/integration/QuickTestIM.py index 3c39df082..cb97e4049 100755 --- a/test/integration/QuickTestIM.py +++ b/test/integration/QuickTestIM.py @@ -541,5 +541,6 @@ def test_75_destroy(self): self.assertTrue( success, msg="ERROR calling DestroyInfrastructure: " + str(res)) + if __name__ == '__main__': unittest.main() diff --git a/test/integration/TestIM.py b/test/integration/TestIM.py index 4ab98780f..e30e962b7 100755 --- a/test/integration/TestIM.py +++ b/test/integration/TestIM.py @@ -685,5 +685,6 @@ def test_95_destroy(self): self.assertTrue( success, msg="ERROR calling DestroyInfrastructure: " + str(res)) + if __name__ == '__main__': unittest.main() diff --git a/test/integration/TestREST.py b/test/integration/TestREST.py index 05b8885b0..d16eb4747 100755 --- a/test/integration/TestREST.py +++ b/test/integration/TestREST.py @@ -477,5 +477,6 @@ def test_98_destroy(self): self.assertEqual(resp.status_code, 200, msg="ERROR destroying the infrastructure:" + resp.text) + if __name__ == '__main__': unittest.main() diff --git a/test/integration/TestREST_JSON.py b/test/integration/TestREST_JSON.py index e7cd9c7c4..f6bb54494 100755 --- a/test/integration/TestREST_JSON.py +++ b/test/integration/TestREST_JSON.py @@ -201,5 +201,6 @@ def test_95_destroy(self): self.assertEqual(resp.status_code, 200, msg="ERROR destroying the infrastructure:" + resp.text) + if __name__ == '__main__': unittest.main() diff --git a/test/loadtest/LoadTest.py b/test/loadtest/LoadTest.py index 129debdf3..684401f13 100755 --- a/test/loadtest/LoadTest.py +++ b/test/loadtest/LoadTest.py @@ -371,6 +371,7 @@ def test(num_client): now = datetime.datetime.now() print(now, ": End client num: %d" % num_client) + if __name__ == '__main__': MAX_THREADS = 1 MAX_CLIENTS = 1 diff --git a/test/loadtest/LoadTestR.py b/test/loadtest/LoadTestR.py index 00025968c..5567ccd89 100755 --- a/test/loadtest/LoadTestR.py +++ b/test/loadtest/LoadTestR.py @@ -118,6 +118,7 @@ def test(num_client): now = datetime.datetime.now() print(now, ": End client num: %d" % num_client) + if __name__ == '__main__': MAX_THREADS = 1 MAX_CLIENTS = 1 diff --git a/test/loadtest/LoadTestREST.py b/test/loadtest/LoadTestREST.py index d7da5e14e..ba105ea92 100755 --- a/test/loadtest/LoadTestREST.py +++ b/test/loadtest/LoadTestREST.py @@ -330,6 +330,7 @@ def test(num_client): now = datetime.datetime.now() print(now, ": End client num: %d" % num_client) + if __name__ == '__main__': MAX_THREADS = 1 MAX_CLIENTS = 1 diff --git a/test/loadtest/LoadTestRESTR.py b/test/loadtest/LoadTestRESTR.py index d668767df..ae2041c5a 100755 --- a/test/loadtest/LoadTestRESTR.py +++ b/test/loadtest/LoadTestRESTR.py @@ -120,6 +120,7 @@ def test(num_client): now = datetime.datetime.now() print(now, ": End client num: %d" % num_client) + if __name__ == '__main__': MAX_THREADS = 1 MAX_CLIENTS = 1 diff --git a/test/unit/REST.py b/test/unit/REST.py index 585b09df6..a3650da77 100755 --- a/test/unit/REST.py +++ b/test/unit/REST.py @@ -779,5 +779,6 @@ def test_format_output(self, get_media_type): info = format_output(["1", "2"]) self.assertEqual(info, 'Unsupported Accept Media Types: application/zip') + if __name__ == "__main__": unittest.main() diff --git a/test/unit/ServiceRequests.py b/test/unit/ServiceRequests.py index a17935161..ce2c6b283 100755 --- a/test/unit/ServiceRequests.py +++ b/test/unit/ServiceRequests.py @@ -172,5 +172,6 @@ def test_version(self, inflist): req = IM.ServiceRequests.IMBaseRequest.create_request(IM.ServiceRequests.IMBaseRequest.GET_VERSION) req._call_function() + if __name__ == '__main__': unittest.main() diff --git a/test/unit/Tosca.py b/test/unit/Tosca.py index b679acc02..89b8546ca 100755 --- a/test/unit/Tosca.py +++ b/test/unit/Tosca.py @@ -92,5 +92,6 @@ def test_tosca_get_outputs(self): 'token': 'pass', 'user': 'ubuntu'}}) + if __name__ == "__main__": unittest.main() diff --git a/test/unit/VMRC.py b/test/unit/VMRC.py index c37770265..219f0bb86 100755 --- a/test/unit/VMRC.py +++ b/test/unit/VMRC.py @@ -98,5 +98,6 @@ def test_list_vm(self, suds_cli): self.assertEqual(res_radl[0].getValue("disk.0.os.credentials.password"), "pass") self.assertEqual(res_radl[0].getValue("disk.0.os.credentials.username"), "user") + if __name__ == '__main__': unittest.main() diff --git a/test/unit/connectors/GCE.py b/test/unit/connectors/GCE.py index 169ba302d..d57f4e8cf 100755 --- a/test/unit/connectors/GCE.py +++ b/test/unit/connectors/GCE.py @@ -406,5 +406,6 @@ def test_70_get_custom_instance(self): instance = gce_cloud.get_instance_type(sizes, radl.systems[0]) self.assertEquals(instance.name, "sizenamne") + if __name__ == '__main__': unittest.main() diff --git a/test/unit/connectors/OpenNebula.py b/test/unit/connectors/OpenNebula.py index dbcb45a4d..9c60c8e1d 100755 --- a/test/unit/connectors/OpenNebula.py +++ b/test/unit/connectors/OpenNebula.py @@ -390,5 +390,6 @@ def test_80_delete_image(self, sleep, getONEVersion, server_proxy): self.assertEqual(one_server.one.image.delete.call_args_list[1], call('user:pass', 1)) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/db.py b/test/unit/db.py index 29b438c1b..95b411c13 100644 --- a/test/unit/db.py +++ b/test/unit/db.py @@ -62,5 +62,6 @@ def test_db(self, mdb_conn): db.close() + if __name__ == '__main__': unittest.main() diff --git a/test/unit/onetts.py b/test/unit/onetts.py index 7017ead4b..917a50e10 100755 --- a/test/unit/onetts.py +++ b/test/unit/onetts.py @@ -47,5 +47,6 @@ def test_list_providers(self, ttscli): self.assertEqual(username, "username", msg="ERROR: getting one auth from TTS, incorrect username.") self.assertEqual(password, "password", msg="ERROR: getting one auth from TTS, incorrect password.") + if __name__ == '__main__': unittest.main() diff --git a/test/unit/openid.py b/test/unit/openid.py index 70a3061a0..514cf59c1 100755 --- a/test/unit/openid.py +++ b/test/unit/openid.py @@ -74,5 +74,6 @@ def test_get_token_introspection(self, requests): self.assertTrue(success) self.assertEqual(json.loads(token_info), token_info_resp) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/recipe.py b/test/unit/recipe.py index 1957c6afc..ad2f416da 100755 --- a/test/unit/recipe.py +++ b/test/unit/recipe.py @@ -51,5 +51,6 @@ def test_recipe(self, DataBase): self.assertEqual(res[0][1], "mod") self.assertEqual(res[0][2], "gmod") + if __name__ == '__main__': unittest.main() diff --git a/test/unit/test_ansible.py b/test/unit/test_ansible.py index c16125931..f1a575714 100755 --- a/test/unit/test_ansible.py +++ b/test/unit/test_ansible.py @@ -49,5 +49,6 @@ def test_ansible_thread(self): self.assertIn("changed=2", output.getvalue()) print(output.getvalue()) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/test_ctxt_agent.py b/test/unit/test_ctxt_agent.py index 6bcbbf7b0..f3f7e94bc 100755 --- a/test/unit/test_ctxt_agent.py +++ b/test/unit/test_ctxt_agent.py @@ -242,5 +242,6 @@ def test_90_replace_vm_ip(self): data = f.read() self.assertIn(" ansible_host=%s ansible_ssh_host=%s \n" % (vm_data['ctxt_ip'], vm_data['ctxt_ip']), data) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/test_ctxt_agent_dist.py b/test/unit/test_ctxt_agent_dist.py index a8d7103fb..9ed1a9eed 100755 --- a/test/unit/test_ctxt_agent_dist.py +++ b/test/unit/test_ctxt_agent_dist.py @@ -279,5 +279,6 @@ def test_90_replace_vm_ip(self): self.assertIn(" ansible_host=%s \n" % vm_data['ctxt_ip'], data) self.assertIn(" ansible_ssh_host=%s \n" % vm_data['ctxt_ip'], data) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/test_im_logic.py b/test/unit/test_im_logic.py index 6ef02633b..486136bd7 100755 --- a/test/unit/test_im_logic.py +++ b/test/unit/test_im_logic.py @@ -1210,5 +1210,6 @@ def test_create_async(self): IM.DestroyInfrastructure(infId, auth0) + if __name__ == "__main__": unittest.main() diff --git a/test/unit/timedcall.py b/test/unit/timedcall.py index 74abc2413..dae9b27b0 100755 --- a/test/unit/timedcall.py +++ b/test/unit/timedcall.py @@ -57,5 +57,6 @@ def test_timer(self): time.sleep(0.1) self.assertEqual(res, 4) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/tts.py b/test/unit/tts.py index d71efe58e..57ebe19a1 100755 --- a/test/unit/tts.py +++ b/test/unit/tts.py @@ -108,5 +108,7 @@ def test_request_credential(self, requests): self.assertTrue(success, msg="ERROR: getting credentials: %s." % cred) self.assertEqual(cred, expected_cred, msg="ERROR: getting credentials: Unexpected credetials.") + + if __name__ == '__main__': unittest.main() diff --git a/test/unit/xmlobject.py b/test/unit/xmlobject.py index 126173479..8b05716ce 100755 --- a/test/unit/xmlobject.py +++ b/test/unit/xmlobject.py @@ -78,5 +78,6 @@ def test_timed_call(self): '512\n\n') self.assertEqual(res, expected) + if __name__ == '__main__': unittest.main()