diff --git a/scciclient/irmc/scci.py b/scciclient/irmc/scci.py index 6dc6d30..9965c83 100755 --- a/scciclient/irmc/scci.py +++ b/scciclient/irmc/scci.py @@ -301,6 +301,16 @@ def scci_cmd(host, userid, password, cmd, port=443, auth_method='basic', if not do_async: time.sleep(5) + else: + # Async mode + # Even in async mode, return immediately may cause error 5 + # (Input/Output error) for some commands such as POWER_ON, + # POWER_OFF, POWER_RESET if we perform multiple calls of them + # in a tight sequence or in parallel. + # So, we sleep some time for such commands. + if cmd in (POWER_ON, POWER_OFF, POWER_RESET): + time.sleep(3) + if DEBUG: print(cmd) print(r.text) diff --git a/scciclient/tests/irmc/test_scci.py b/scciclient/tests/irmc/test_scci.py index 2573e15..300045a 100644 --- a/scciclient/tests/irmc/test_scci.py +++ b/scciclient/tests/irmc/test_scci.py @@ -270,7 +270,8 @@ class SCCITestCase(testtools.TestCase): 'HTTP PROTOCOL ERROR, STATUS CODE = 302', str(e)) - def test_power_on_ok(self): + @mock.patch.object(time, 'sleep') + def test_power_on_ok(self, mock_sleep): self.requests_mock.post("http://" + self.irmc_address + "/config", text=""" @@ -287,8 +288,10 @@ class SCCITestCase(testtools.TestCase): client_timeout=self.irmc_client_timeout) r = client(scci.POWER_ON) self.assertEqual(r.status_code, 200) + mock_sleep.assert_called_once_with(3) - def test_power_off_ok(self): + @mock.patch.object(time, 'sleep') + def test_power_off_ok(self, mock_sleep): self.requests_mock.post("http://" + self.irmc_address + "/config", text=""" @@ -305,6 +308,7 @@ class SCCITestCase(testtools.TestCase): client_timeout=self.irmc_client_timeout) r = client(scci.POWER_OFF) self.assertEqual(r.status_code, 200) + mock_sleep.assert_called_once_with(3) def test_power_cycle_ok(self): self.requests_mock.post("http://" + self.irmc_address + "/config", @@ -324,7 +328,8 @@ class SCCITestCase(testtools.TestCase): r = client(scci.POWER_CYCLE) self.assertEqual(r.status_code, 200) - def test_power_reset_ok(self): + @mock.patch.object(time, 'sleep') + def test_power_reset_ok(self, mock_sleep): self.requests_mock.post("http://" + self.irmc_address + "/config", text=""" @@ -341,6 +346,7 @@ class SCCITestCase(testtools.TestCase): client_timeout=self.irmc_client_timeout) r = client(scci.POWER_RESET) self.assertEqual(r.status_code, 200) + mock_sleep.assert_called_once_with(3) def test_power_raise_nmi_ok(self): self.requests_mock.post("http://" + self.irmc_address + "/config",