Beispiel #1
0
 def test_ensure_get_called_valid_volume(self, mock_base, client_f):
     set_module_args(self.set_default_args())
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     my_obj = volume_module()
     my_obj.netapp_client.volumes = self.netapp_client.volumes
     assert my_obj.get_azure_netapp_volume() is not None
Beispiel #2
0
 def test_ensure_get_called_valid_capacity_pool(self, client_f, mock_base):
     set_module_args(self.set_default_args())
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     my_obj = capacity_pool_module()
     my_obj.netapp_client.pools = self.netapp_client.pools
     assert my_obj.get_azure_netapp_capacity_pool() is not None
 def test_ensure_get_called_valid_account(self, client_f, mock_base):
     set_module_args(self.set_default_args())
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     client_f.side_effect = Mock()
     my_obj = account_module()
     # my_obj.netapp_client = self.netapp_client
     my_obj.netapp_client.accounts = self.netapp_client.accounts
     assert my_obj.get_azure_netapp_account() is not None
Beispiel #4
0
 def test_ensure_get_called_non_existing_volume(self, mock_base, client_f):
     data = self.set_default_args()
     data['name'] = 'invalid'
     set_module_args(data)
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     my_obj = volume_module()
     my_obj.netapp_client.volumes = self.netapp_client.volumes
     assert my_obj.get_azure_netapp_volume() is None
Beispiel #5
0
 def test_ensure_get_called_non_existing_capacity_pool(
         self, client_f, mock_base):
     data = self.set_default_args()
     data['name'] = 'invalid'
     set_module_args(data)
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     my_obj = capacity_pool_module()
     my_obj.netapp_client.pools = self.netapp_client.pools
     assert my_obj.get_azure_netapp_capacity_pool() is None
 def test_ensure_get_called_non_existing_account(self, client_f, mock_base):
     data = self.set_default_args()
     data['name'] = 'invalid'
     set_module_args(data)
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     client_f.side_effect = Mock()
     my_obj = account_module()
     my_obj.netapp_client.accounts = self.netapp_client.accounts
     assert my_obj.get_azure_netapp_account() is None
Beispiel #7
0
 def test_ensure_delete_called(self, client_f, mock_delete, mock_get,
                               mock_base):
     data = self.set_default_args()
     data['state'] = 'absent'
     set_module_args(data)
     mock_base.return_value = Mock()
     mock_get.return_value = Mock()
     my_obj = capacity_pool_module()
     my_obj.netapp_client.pools = self.netapp_client.pools
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.exec_module()
     assert exc.value.args[0]['changed']
     mock_delete.assert_called_with()
Beispiel #8
0
 def test_ensure_create_called(self, mock_create, mock_get, mock_base, client_f):
     data = self.set_default_args()
     data['name'] = 'create'
     set_module_args(data)
     mock_get.return_value = None
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     my_obj = volume_module()
     my_obj.netapp_client.volumes = self.netapp_client.volumes
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.exec_module()
     assert exc.value.args[0]['changed']
     mock_create.assert_called_with()
Beispiel #9
0
 def test_ensure_modify_called(self, client_f, mock_modify, mock_get,
                               mock_base):
     data = self.set_default_args()
     data['name'] = 'create'
     data['size'] = 3
     set_module_args(data)
     mock_get.return_value = None
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     my_obj = capacity_pool_module()
     my_obj.netapp_client.pools = self.netapp_client.pools
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.exec_module()
     assert exc.value.args[0]['changed']
     mock_modify.assert_called_with()
Beispiel #10
0
 def test_ensure_create_called_but_fail_on_mount_target(
         self, mock_create, mock_get, mock_base, client_f):
     data = self.set_default_args()
     data['name'] = 'create'
     set_module_args(data)
     mock_get.return_value = None
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     my_obj = volume_module()
     my_obj.netapp_client.volumes = self.netapp_client.volumes
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.exec_module()
     error = 'Error: volume create was created successfully, but cannot be found.'
     assert exc.value.args[0]['msg'] == error
     mock_create.assert_called_with()
Beispiel #11
0
 def get(self, resource_group, account_name, pool_name):  # pylint: disable=unused-argument
     if pool_name not in self.valid_pools:
         invalid = Response()
         invalid.status_code = 404
         raise CloudError(response=invalid)
     else:
         return Mock(name=pool_name)
Beispiel #12
0
 def test_ensure_create_called(self, client_f, mock_create, mock_get,
                               mock_base):
     data = self.set_default_args()
     data['name'] = 'create'
     data['tags'] = {'ttt': 'tesssttt', 'abc': 'xyz'}
     set_module_args(data)
     mock_get.return_value = None
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     client_f.side_effect = Mock()
     my_obj = account_module()
     my_obj.netapp_client.accounts = self.netapp_client.accounts
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.exec_module()
     assert exc.value.args[0]['changed']
     mock_create.assert_called_with()
Beispiel #13
0
 def setUp(self):
     self.mock_module_helper = patch.multiple(basic.AnsibleModule,
                                              exit_json=exit_json,
                                              fail_json=fail_json)
     self.mock_module_helper.start()
     self.addCleanup(self.mock_module_helper.stop)
     self.netapp_client = Mock()
     self.netapp_client.pools = MockAzureClient()
     self._netapp_client = None
Beispiel #14
0
 def test_ensure_create_called_but_fail_on_get(self, mock_create, mock_get,
                                               mock_base, client_f):
     data = self.set_default_args()
     data['name'] = 'create'
     set_module_args(data)
     mock_get.side_effect = [
         None,  # first get
         Mock(
             mount_targets=None,  # get after create
             creation_token='abcd')
     ]
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     my_obj = volume_module()
     my_obj.netapp_client.volumes = self.netapp_client.volumes
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.exec_module()
     error = 'Error: volume create was created successfully, but mount target(s) cannot be found - volume details:'
     assert exc.value.args[0]['msg'].startswith(error)
     mock_create.assert_called_with()
Beispiel #15
0
 def test_ensure_create_called(self, mock_create, mock_get, mock_base,
                               client_f):
     data = self.set_default_args()
     data['name'] = 'create'
     set_module_args(data)
     mock_get.side_effect = [
         None,  # first get
         Mock(
             mount_targets=[Mock(ip_address='11.22.33.44')
                            ],  # get after create
             creation_token='abcd')
     ]
     mock_base.return_value = Mock()
     client_f.return_value = Mock()
     my_obj = volume_module()
     my_obj.netapp_client.volumes = self.netapp_client.volumes
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.exec_module()
     assert exc.value.args[0]['changed']
     expected_msg = '11.22.33.44:/abcd'
     assert exc.value.args[0]['msg'] == expected_msg
     mock_create.assert_called_with()