"Remove unused lines of code"
Change-Id: I02be0efe4918083d95a4017c898bfabaf269e779
Signed-off-by: David Garcia <david.garcia@canonical.com>
diff --git a/n2vc/tests/unit/test_juju_observer.py b/n2vc/tests/unit/test_juju_observer.py
deleted file mode 100644
index f40824e..0000000
--- a/n2vc/tests/unit/test_juju_observer.py
+++ /dev/null
@@ -1,159 +0,0 @@
-# Copyright 2020 Canonical Ltd.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-import asyncio
-from unittest import mock
-from unittest.mock import Mock
-
-import asynctest
-
-from n2vc.exceptions import N2VCTimeoutException
-from n2vc.juju_observer import JujuModelObserver, _Entity
-
-
-class FakeObject:
- def __init__(self):
- self.complete = True
-
-
-class JujuModelObserverTest(asynctest.TestCase):
- def setUp(self):
- self.n2vc = Mock()
- self.model = Mock()
- self.juju_observer = JujuModelObserver(n2vc=self.n2vc, model=self.model)
- self.loop = asyncio.new_event_loop()
-
- def test_wait_no_retries(self):
- obj = FakeObject()
- entity = _Entity(entity_id="eid-1", entity_type="fake", obj=obj, db_dict={})
- result = self.loop.run_until_complete(
- self.juju_observer._wait_for_entity(
- entity=entity,
- field_to_check="complete",
- final_states_list=[True],
- progress_timeout=None,
- total_timeout=None,
- )
- )
- self.assertEqual(result, 0)
-
- @mock.patch("n2vc.juju_observer.asyncio.wait_for")
- def test_wait_default_values(self, wait_for):
- wait_for.return_value = asyncio.Future()
- wait_for.return_value.set_result(None)
- obj = FakeObject()
- obj.complete = False
- entity = _Entity(entity_id="eid-1", entity_type="fake", obj=obj, db_dict={})
- with self.assertRaises(N2VCTimeoutException):
- self.loop.run_until_complete(
- self.juju_observer._wait_for_entity(
- entity=entity,
- field_to_check="complete",
- final_states_list=[True],
- progress_timeout=None,
- total_timeout=None,
- )
- )
- wait_for.assert_called_once_with(fut=mock.ANY, timeout=3600.0)
-
- @mock.patch("n2vc.juju_observer.asyncio.wait_for")
- def test_wait_default_progress(self, wait_for):
- wait_for.return_value = asyncio.Future()
- wait_for.return_value.set_result(None)
- obj = FakeObject()
- obj.complete = False
- entity = _Entity(entity_id="eid-1", entity_type="fake", obj=obj, db_dict={})
- with self.assertRaises(N2VCTimeoutException):
- self.loop.run_until_complete(
- self.juju_observer._wait_for_entity(
- entity=entity,
- field_to_check="complete",
- final_states_list=[True],
- progress_timeout=4000,
- total_timeout=None,
- )
- )
- wait_for.assert_called_once_with(fut=mock.ANY, timeout=3600.0)
-
- @mock.patch("n2vc.juju_observer.asyncio.wait_for")
- def test_wait_default_total(self, wait_for):
- wait_for.return_value = asyncio.Future()
- wait_for.return_value.set_result(None)
- obj = FakeObject()
- obj.complete = False
- entity = _Entity(entity_id="eid-1", entity_type="fake", obj=obj, db_dict={})
- with self.assertRaises(N2VCTimeoutException):
- self.loop.run_until_complete(
- self.juju_observer._wait_for_entity(
- entity=entity,
- field_to_check="complete",
- final_states_list=[True],
- progress_timeout=None,
- total_timeout=4000.0,
- )
- )
- wait_for.assert_called_once_with(fut=mock.ANY, timeout=3600.0)
-
- @mock.patch("n2vc.juju_observer.asyncio.wait_for")
- def test_wait_total_less_than_progress_timeout(self, wait_for):
- wait_for.return_value = asyncio.Future()
- wait_for.return_value.set_result(None)
- obj = FakeObject()
- obj.complete = False
- entity = _Entity(entity_id="eid-1", entity_type="fake", obj=obj, db_dict={})
- with self.assertRaises(N2VCTimeoutException):
- self.loop.run_until_complete(
- self.juju_observer._wait_for_entity(
- entity=entity,
- field_to_check="complete",
- final_states_list=[True],
- progress_timeout=4500.0,
- total_timeout=3000.0,
- )
- )
- wait_for.assert_called_once_with(fut=mock.ANY, timeout=3000.0)
-
- @mock.patch("n2vc.juju_observer.asyncio.wait_for")
- def test_wait_progress_less_than_total_timeout(self, wait_for):
- wait_for.return_value = asyncio.Future()
- wait_for.return_value.set_result(None)
- obj = FakeObject()
- obj.complete = False
- entity = _Entity(entity_id="eid-1", entity_type="fake", obj=obj, db_dict={})
- with self.assertRaises(N2VCTimeoutException):
- self.loop.run_until_complete(
- self.juju_observer._wait_for_entity(
- entity=entity,
- field_to_check="complete",
- final_states_list=[True],
- progress_timeout=1500.0,
- total_timeout=3000.0,
- )
- )
- wait_for.assert_called_once_with(fut=mock.ANY, timeout=1500.0)
-
- def test_wait_negative_timeout(self):
- obj = FakeObject()
- entity = _Entity(entity_id="eid-1", entity_type="fake", obj=obj, db_dict={})
- with self.assertRaises(N2VCTimeoutException):
- self.loop.run_until_complete(
- self.juju_observer._wait_for_entity(
- entity=entity,
- field_to_check="complete",
- final_states_list=[True],
- progress_timeout=None,
- total_timeout=-1000,
- )
- )
diff --git a/n2vc/tests/unit/test_provisioner.py b/n2vc/tests/unit/test_provisioner.py
index 880c5cb..a4572b3 100644
--- a/n2vc/tests/unit/test_provisioner.py
+++ b/n2vc/tests/unit/test_provisioner.py
@@ -12,147 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from unittest import TestCase, mock
-
-from mock import mock_open
-from n2vc.provisioner import SSHProvisioner
-from paramiko.ssh_exception import SSHException
+from unittest import TestCase
class ProvisionerTest(TestCase):
def setUp(self):
- self.provisioner = SSHProvisioner(None, None, None)
-
- @mock.patch("n2vc.provisioner.os.path.exists")
- @mock.patch("n2vc.provisioner.paramiko.RSAKey")
- @mock.patch("n2vc.provisioner.paramiko.SSHClient")
- @mock.patch("builtins.open", new_callable=mock_open, read_data="data")
- def test__get_ssh_client(self, _mock_open, mock_sshclient, _mock_rsakey, _mock_os):
- mock_instance = mock_sshclient.return_value
- sshclient = self.provisioner._get_ssh_client()
- self.assertEqual(mock_instance, sshclient)
- self.assertEqual(
- 1,
- mock_instance.set_missing_host_key_policy.call_count,
- "Missing host key call count",
- )
- self.assertEqual(1, mock_instance.connect.call_count, "Connect call count")
-
- @mock.patch("n2vc.provisioner.os.path.exists")
- @mock.patch("n2vc.provisioner.paramiko.RSAKey")
- @mock.patch("n2vc.provisioner.paramiko.SSHClient")
- @mock.patch("builtins.open", new_callable=mock_open, read_data="data")
- def test__get_ssh_client_no_connection(
- self, _mock_open, mock_sshclient, _mock_rsakey, _mock_os
- ):
-
- mock_instance = mock_sshclient.return_value
- mock_instance.method_inside_someobject.side_effect = ["something"]
- mock_instance.connect.side_effect = SSHException()
-
- self.assertRaises(SSHException, self.provisioner._get_ssh_client)
- self.assertEqual(
- 1,
- mock_instance.set_missing_host_key_policy.call_count,
- "Missing host key call count",
- )
- self.assertEqual(1, mock_instance.connect.call_count, "Connect call count")
-
- @mock.patch("n2vc.provisioner.os.path.exists")
- @mock.patch("n2vc.provisioner.paramiko.RSAKey")
- @mock.patch("n2vc.provisioner.paramiko.SSHClient")
- @mock.patch("builtins.open", new_callable=mock_open, read_data="data")
- def test__get_ssh_client_bad_banner(
- self, _mock_open, mock_sshclient, _mock_rsakey, _mock_os
- ):
-
- mock_instance = mock_sshclient.return_value
- mock_instance.method_inside_someobject.side_effect = ["something"]
- mock_instance.connect.side_effect = [
- SSHException("Error reading SSH protocol banner"),
- None,
- None,
- ]
-
- sshclient = self.provisioner._get_ssh_client()
- self.assertEqual(mock_instance, sshclient)
- self.assertEqual(
- 1,
- mock_instance.set_missing_host_key_policy.call_count,
- "Missing host key call count",
- )
- self.assertEqual(
- 3, mock_instance.connect.call_count, "Should attempt 3 connections"
- )
-
- @mock.patch("time.sleep", autospec=True)
- @mock.patch("n2vc.provisioner.os.path.exists")
- @mock.patch("n2vc.provisioner.paramiko.RSAKey")
- @mock.patch("n2vc.provisioner.paramiko.SSHClient")
- @mock.patch("builtins.open", new_callable=mock_open, read_data="data")
- def test__get_ssh_client_unable_to_connect(
- self, _mock_open, mock_sshclient, _mock_rsakey, _mock_os, _mock_sleep
- ):
-
- mock_instance = mock_sshclient.return_value
- mock_instance.connect.side_effect = Exception("Unable to connect to port")
-
- self.assertRaises(Exception, self.provisioner._get_ssh_client)
- self.assertEqual(
- 1,
- mock_instance.set_missing_host_key_policy.call_count,
- "Missing host key call count",
- )
- self.assertEqual(
- 11, mock_instance.connect.call_count, "Should attempt 11 connections"
- )
-
- @mock.patch("time.sleep", autospec=True)
- @mock.patch("n2vc.provisioner.os.path.exists")
- @mock.patch("n2vc.provisioner.paramiko.RSAKey")
- @mock.patch("n2vc.provisioner.paramiko.SSHClient")
- @mock.patch("builtins.open", new_callable=mock_open, read_data="data")
- def test__get_ssh_client_unable_to_connect_once(
- self, _mock_open, mock_sshclient, _mock_rsakey, _mock_os, _mock_sleep
- ):
-
- mock_instance = mock_sshclient.return_value
- mock_instance.connect.side_effect = [
- Exception("Unable to connect to port"),
- None,
- ]
-
- sshclient = self.provisioner._get_ssh_client()
- self.assertEqual(mock_instance, sshclient)
- self.assertEqual(
- 1,
- mock_instance.set_missing_host_key_policy.call_count,
- "Missing host key call count",
- )
- self.assertEqual(
- 2, mock_instance.connect.call_count, "Should attempt 2 connections"
- )
-
- @mock.patch("n2vc.provisioner.os.path.exists")
- @mock.patch("n2vc.provisioner.paramiko.RSAKey")
- @mock.patch("n2vc.provisioner.paramiko.SSHClient")
- @mock.patch("builtins.open", new_callable=mock_open, read_data="data")
- def test__get_ssh_client_other_exception(
- self, _mock_open, mock_sshclient, _mock_rsakey, _mock_os
- ):
-
- mock_instance = mock_sshclient.return_value
- mock_instance.connect.side_effect = Exception()
-
- self.assertRaises(Exception, self.provisioner._get_ssh_client)
- self.assertEqual(
- 1,
- mock_instance.set_missing_host_key_policy.call_count,
- "Missing host key call count",
- )
- self.assertEqual(
- 1, mock_instance.connect.call_count, "Should only attempt 1 connection"
- )
-
-
-#
+ pass