Beispiel #1
0
 def _test_vnc_read_with_job_params(self):
     fake_vnc_lib = flexmock()
     flexmock(JobVncApi).should_receive('vnc_init').and_return(fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router = PhysicalRouter(name='test-tenant')
     fake_router_obj = {"physical-router": {"name": "Router-1"}}
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_read').and_return(fake_router)
     flexmock(fake_vnc_lib).should_receive('obj_to_dict').and_return(
         fake_router_obj)
     set_module_args(
         dict(
             object_type='physical_router',
             object_op='read',
             object_dict={"uuid": "1234"},
             job_ctx={
                 "auth_token":
                 "1234",
                 "job_template_fqname":
                 ["default-global-system-config", "device_import_template"],
                 "job_execution_id":
                 "123",
                 "config_args":
                 "546",
                 "job_input":
                 ""
             }))
     result = self.execute_module()
     self.assertEqual(result.get('failed'), None)
 def test_fileutility01(self):
     fake_image_url = "/v1/sample.txt"
     flexmock(swiftclient.utils).should_receive('generate_temp_url').and_return(fake_image_url)
     set_module_args(self.args_dict)
     result = self.execute_module()
     self.assertTrue(result["url"])
     self.assertEqual(result["url"], fake_image_url)
Beispiel #3
0
 def _test_vnc_bulk_create(self):
     object_list = [{
         "parent_type": "global-system-config",
         "fq_name": ["default-global-system-config", "mx-240"],
         "physical_router_management_ip": "172.10.68.1",
         "physical_router_vendor_name": "Juniper",
         "physical_router_product_name": "MX",
         "physical_router_device_family": "junos"
     }]
     fake_vnc_lib = flexmock()
     flexmock(JobVncApi).should_receive('vnc_init').and_return(fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router_uuid = "1ef6cf9d-c2e2-4004-810a-43d471c94dc5"
     fake_router = PhysicalRouter(name='mx-240')
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_read').and_return(fake_router)
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_create').and_return(fake_router_uuid)
     set_module_args(
         dict(enable_job_ctx=False,
              object_type='physical_router',
              object_op='bulk_create',
              object_list=object_list,
              job_ctx={"auth_token": "1234"}))
     result = self.execute_module()
     self.assertEqual(result.get('failed'), None)
Beispiel #4
0
 def test_auth_token_not_present(self):
     set_module_args(
         dict(object_type='physical_router',
              object_op='get',
              object_dict={"uuid": "1234"}))
     result = self.execute_module(failed=True)
     self.assertEqual(result['failed'], True)
 def test_fileutility01(self):
     fake_image_url = "/v1/sample.txt"
     flexmock(swiftclient.utils).should_receive('generate_temp_url').and_return(fake_image_url)
     set_module_args(self.args_dict)
     result = self.execute_module()
     self.assertTrue(result["url"])
     self.assertEqual(result["url"], fake_image_url)
 def test_auth_token_not_present(self):
     set_module_args(
         dict(enable_job_ctx=False, object_type='physical_router',
              object_op='get',
              object_dict={"uuid": "1234"}, job_ctx={}))
     result = self.execute_module(failed=True)
     self.assertEqual(result['failed'], True)
 def test_object_type_not_present(self):
     set_module_args(
         dict(enable_job_ctx=False,
              object_op='get',
              object_dict={"uuid": "1234"},
              job_ctx={"auth_token": "1234"}))
     result = self.execute_module(failed=True)
     self.assertEqual(result['failed'], True)
Beispiel #8
0
 def _test_job_ctx_not_present(self):
     set_module_args(
         dict(enable_job_ctx=False,
              object_type='physical_router',
              object_op='get',
              object_dict={"uuid": "1234"}))
     result = self.execute_module(failed=True)
     self.assertEqual(result['failed'], True)
Beispiel #9
0
 def _test_invalid_vnc_class(self):
     set_module_args(
         dict(object_type='lldp',
              object_op='get',
              object_dict={"uuid": "1234"},
              auth_token="1234"))
     result = self.execute_module(failed=True)
     self.assertEqual(result['failed'], True)
 def test_fileutility06(self):
     for e in ["tenant_name","auth_version","chosen_temp_url_key","connection_retry_count"]:
         self.args_dict.pop(e, None)
     set_module_args(self.args_dict)
     fake_image_url = "/v1/sample.txt"
     flexmock(swiftclient.utils).should_receive('generate_temp_url').and_return(fake_image_url)
     result = self.execute_module()
     self.assertTrue(result["url"])
     self.assertEqual(result["url"], fake_image_url)
 def test_fileutility06(self):
     for e in ["tenant_name","auth_version","chosen_temp_url_key","connection_retry_count"]:
         self.args_dict.pop(e, None)
     set_module_args(self.args_dict)
     fake_image_url = "/v1/sample.txt"
     flexmock(swiftclient.utils).should_receive('generate_temp_url').and_return(fake_image_url)
     result = self.execute_module()
     self.assertTrue(result["url"])
     self.assertEqual(result["url"], fake_image_url)
Beispiel #12
0
 def _test_invalid_vnc_op(self):
     set_module_args(
         dict(enable_job_ctx=False,
              object_type='physical_router',
              object_op='get',
              object_dict={"uuid": "1234"},
              job_ctx={"auth_token": "1234"}))
     result = self.execute_module(failed=True)
     self.assertEqual(result['failed'], True)
 def test_vnc_read(self):
     fake_vnc_lib = flexmock()
     flexmock(VncApi, __new__=fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router = PhysicalRouter(name='test-tenant')
     fake_router_obj = {"physical-router": {"name": "Router-1"}}
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_read').and_return(fake_router)
     flexmock(fake_vnc_lib).should_receive(
         'obj_to_dict').and_return(fake_router_obj)
     set_module_args(
         dict(enable_job_ctx=False, object_type='physical_router',
              object_op='read', object_dict={"uuid": "1234"},
              job_ctx={"auth_token": "1234"}))
     result = self.execute_module()
     self.assertEqual(result.get('failed'), None)
Beispiel #14
0
 def test_vnc_read(self):
     fake_vnc_lib = flexmock()
     flexmock(VncApi, __new__=fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router = PhysicalRouter(name='test-tenant')
     fake_router_obj = {"physical-router": {"name": "Router-1"}}
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_read').and_return(fake_router)
     flexmock(fake_vnc_lib).should_receive('obj_to_dict').and_return(
         fake_router_obj)
     set_module_args(
         dict(object_type='physical_router',
              object_op='read',
              object_dict={"uuid": "1234"},
              auth_token="1234"))
     result = self.execute_module()
     self.assertEqual(result['failed'], False)
 def test_fileutility06(self):
     self.args_dict = dict(authtoken="4242",
                           authurl="auth_url",
                           user="******",
                           key="contrail",
                           temp_url_key="temp_url_key1",
                           temp_url_key_2="temp_url_key2",
                           container_name="container",
                           filename="sample.txt",
                           expirytime=3600)
     set_module_args(self.args_dict)
     fake_image_url = "/v1/sample.txt"
     flexmock(swiftclient.utils).should_receive(
         'generate_temp_url').and_return(fake_image_url)
     result = self.execute_module()
     self.assertTrue(result["url"])
     self.assertEqual(result["url"], fake_image_url)
Beispiel #16
0
 def _test_vnc_read(self):
     fake_vnc_lib = flexmock()
     flexmock(JobVncApi).should_receive('vnc_init').and_return(fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router = PhysicalRouter(name='test-tenant')
     fake_router_obj = {"physical-router": {"name": "Router-1"}}
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_read').and_return(fake_router)
     flexmock(fake_vnc_lib).should_receive('obj_to_dict').and_return(
         fake_router_obj)
     set_module_args(
         dict(enable_job_ctx=False,
              object_type='physical_router',
              object_op='read',
              object_dict={"uuid": "1234"},
              job_ctx={"auth_token": "1234"}))
     result = self.execute_module()
     self.assertEqual(result.get('failed'), None)
 def test_vnc_create(self):
     object_dict = {"parent_type": "global-system-config",
                    "fq_name": ["default-global-system-config", "mx-240"],
                    "physical_router_management_ip": "172.10.68.1",
                    "physical_router_vendor_name": "Juni",
                    "physical_router_product_name": "MX",
                    "physical_router_device_family": "junos"}
     fake_vnc_lib = flexmock()
     flexmock(VncApi, __new__=fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router_uuid = "1ef6cf9d-c2e2-4004-810a-43d471c94dc5"
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_create').and_return(fake_router_uuid)
     set_module_args(
         dict(enable_job_ctx=False, object_type='physical_router',
              object_op='create', object_dict=object_dict,
              job_ctx={"auth_token": "1234"}))
     result = self.execute_module()
     self.assertEqual(result.get('failed'), None)
 def test_vnc_read_with_job_params(self):
     fake_vnc_lib = flexmock()
     flexmock(VncApi, __new__=fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router = PhysicalRouter(name='test-tenant')
     fake_router_obj = {"physical-router": {"name": "Router-1"}}
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_read').and_return(fake_router)
     flexmock(fake_vnc_lib).should_receive(
         'obj_to_dict').and_return(fake_router_obj)
     set_module_args(
         dict(object_type='physical_router',
              object_op='read', object_dict={"uuid": "1234"},
              job_ctx={"auth_token": "1234",
                       "job_template_fqname": [
                           "default-global-system-config",
                           "device_import_template"],
                       "job_execution_id": "123",
                       "config_args": "546", "job_input": ""}))
     result = self.execute_module()
     self.assertEqual(result.get('failed'), None)
Beispiel #19
0
 def test_vnc_create(self):
     object_dict = {
         "parent_type": "global-system-config",
         "fq_name": ["default-global-system-config", "mx-240"],
         "physical_router_management_ip": "172.10.68.1",
         "physical_router_vendor_name": "Juni",
         "physical_router_product_name": "MX",
         "physical_router_device_family": "juniper-mx"
     }
     fake_vnc_lib = flexmock()
     flexmock(VncApi, __new__=fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router_uuid = "1ef6cf9d-c2e2-4004-810a-43d471c94dc5"
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_create').and_return(fake_router_uuid)
     set_module_args(
         dict(object_type='physical_router',
              object_op='create',
              object_dict=object_dict,
              auth_token="1234"))
     result = self.execute_module()
     self.assertEqual(result['failed'], False)
 def test_vnc_bulk_update(self):
     object_list = [{
         "uuid": "1ef6cf9d-c2e2-4004-810a-43d471c94dc5",
         "physical_router_user_credentials": {
             "username": "******",
             "password": "******"
         }
     }]
     fake_vnc_lib = flexmock()
     flexmock(VncApi, __new__=fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router_obj = "{'physical-router' : {'uuid': '1ef6cf9d-c2e2-4004-810a-43d471c94dc5'}}"
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_update').and_return(fake_router_obj)
     flexmock(fake_vnc_lib).should_receive(
         'id_to_fq_name').and_return('MX-240')
     set_module_args(
         dict(enable_job_ctx=False, object_type='physical_router',
              object_op='bulk_update', object_list=object_list,
              job_ctx={"auth_token": "1234"}))
     result = self.execute_module()
     self.assertEqual(result.get('failed'), None)
Beispiel #21
0
 def test_vnc_update(self):
     object_dict = {
         "uuid": "1ef6cf9d-c2e2-4004-810a-43d471c94dc5",
         "physical_router_user_credentials": {
             "username": "******",
             "password": "******"
         }
     }
     fake_vnc_lib = flexmock()
     flexmock(VncApi, __new__=fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router_obj = "{'physical-router' : {'uuid': '1ef6cf9d-c2e2-4004-810a-43d471c94dc5'}}"
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_update').and_return(fake_router_obj)
     flexmock(fake_vnc_lib).should_receive('id_to_fq_name').and_return(
         'MX-240')
     set_module_args(
         dict(object_type='physical_router',
              object_op='update',
              object_dict=object_dict,
              auth_token="1234"))
     result = self.execute_module()
     self.assertEqual(result['failed'], False)
Beispiel #22
0
 def _test_vnc_bulk_update(self):
     object_list = [{
         "uuid": "1ef6cf9d-c2e2-4004-810a-43d471c94dc5",
         "physical_router_user_credentials": {
             "username": "******",
             "password": "******"
         }
     }]
     fake_vnc_lib = flexmock()
     flexmock(JobVncApi).should_receive('vnc_init').and_return(fake_vnc_lib)
     fake_vnc_lib.should_receive('__init__')
     fake_router_obj = "{'physical-router' : {'uuid': '1ef6cf9d-c2e2-4004-810a-43d471c94dc5'}}"
     flexmock(fake_vnc_lib).should_receive(
         'physical_router_update').and_return(fake_router_obj)
     flexmock(fake_vnc_lib).should_receive('id_to_fq_name').and_return(
         'MX-240')
     set_module_args(
         dict(enable_job_ctx=False,
              object_type='physical_router',
              object_op='bulk_update',
              object_list=object_list,
              job_ctx={"auth_token": "1234"}))
     result = self.execute_module()
     self.assertEqual(result.get('failed'), None)
 def test_fileutility04(self):
     flexmock(
         swiftclient.client).should_receive('Connection').and_return(None)
     set_module_args(self.args_dict)
     self.assertRaises(Exception, self.execute_module())
 def test_invalid_vnc_class(self):
     set_module_args(dict(object_type='lldp', object_op='get',
                          object_dict={"uuid": "1234"}, auth_token="1234"))
     result = self.execute_module(failed=True)
     self.assertEqual(result['failed'], True)
 def test_fileutility_03(self):
     flexmock(swiftclient.utils).should_receive('generate_temp_url').and_raise(Exception)
     set_module_args(self.args_dict)
     self.assertRaises(Exception, self.execute_module())
 def test_fileutility04(self):
     flexmock(swiftclient.client).should_receive('Connection').and_return(None)
     self.args_dict['connection_retry_count'] = 1
     set_module_args(self.args_dict)
     self.assertRaises(Exception, self.execute_module())
 def test_fileutility05(self):
     flexmock(self.mockobj).should_receive('post_account').and_raise(Exception)
     set_module_args(self.args_dict)
     self.assertRaises(Exception, self.execute_module())
 def test_fileutility_03(self):
     flexmock(swiftclient.utils).should_receive(
         'generate_temp_url').and_raise(Exception)
     set_module_args(self.args_dict)
     self.assertRaises(Exception, self.execute_module())
 def test_fileutility05(self):
     flexmock(
         self.mockobj).should_receive('post_account').and_raise(Exception)
     set_module_args(self.args_dict)
     self.assertRaises(Exception, self.execute_module())