Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions awscli/customizations/codedeploy/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def install(self, params):
'-Name', 'codedeployagent'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
)
(output, error) = process.communicate()
not_found = (
Expand Down Expand Up @@ -102,7 +103,8 @@ def install(self, params):
'-Name', 'codedeployagent'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
)
(output, error) = process.communicate()
if "Running" not in output:
Expand All @@ -118,7 +120,8 @@ def uninstall(self, params):
'-Name', 'codedeployagent'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
)
(output, error) = process.communicate()
not_found = (
Expand All @@ -139,7 +142,8 @@ def _remove_agent(self):
'call', 'uninstall', '/nointeractive'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
)
(output, error) = process.communicate()
if process.returncode != 0:
Expand Down Expand Up @@ -202,7 +206,8 @@ def _stop_agent(self, params):
process = subprocess.Popen(
['service', 'codedeploy-agent', 'stop'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
)
(output, error) = process.communicate()
if process.returncode != 0 and params.not_found_msg not in error:
Expand Down
90 changes: 82 additions & 8 deletions tests/unit/customizations/codedeploy/test_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def test_install(self):
'-Name', 'codedeployagent'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
),
mock.call().communicate(),
mock.call(
Expand All @@ -98,7 +99,8 @@ def test_install(self):
'-Name', 'codedeployagent'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
),
mock.call().communicate()
])
Expand Down Expand Up @@ -134,7 +136,8 @@ def test_uninstall(self):
'-Name', 'codedeployagent'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
),
mock.call().communicate(),
mock.call(
Expand All @@ -144,11 +147,38 @@ def test_uninstall(self):
'call', 'uninstall', '/nointeractive'
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
),
mock.call().communicate()
])

def test_install_service_not_found(self):
not_found = (
"Cannot find any service with service name 'codedeployagent'"
)
stop_process = mock.MagicMock()
stop_process.communicate.return_value = ('', not_found)
stop_process.returncode = 1

get_process = mock.MagicMock()
get_process.communicate.return_value = ('Running', '')
get_process.returncode = 0

self.popen.side_effect = [stop_process, get_process]
self.windows.install(self.params)

def test_uninstall_service_not_found(self):
not_found = (
"Cannot find any service with service name 'codedeployagent'"
)
process = mock.MagicMock()
process.communicate.return_value = ('', not_found)
process.returncode = 1
self.popen.return_value = process
self.windows.uninstall(self.params)
self.assertEqual(self.popen.call_count, 1)


class TestLinux(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -248,7 +278,8 @@ def test_install(self):
mock.call(
['service', 'codedeploy-agent', 'stop'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
),
mock.call().communicate()
])
Expand All @@ -274,14 +305,35 @@ def test_uninstall(self):
mock.call(
['service', 'codedeploy-agent', 'stop'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
),
mock.call().communicate()
])
self.check_call.assert_has_calls([
mock.call(['dpkg', '-r', 'codedeploy-agent'])
])

def test_install_service_not_found(self):
process = mock.MagicMock()
process.communicate.return_value = (
'', 'codedeploy-agent: unrecognized service'
)
process.returncode = 1
self.popen.return_value = process
self.ubuntu.install(self.params)

def test_uninstall_service_not_found(self):
process = mock.MagicMock()
process.communicate.return_value = (
'', 'codedeploy-agent: unrecognized service'
)
process.returncode = 1
self.popen.return_value = process
self.ubuntu.uninstall(self.params)
self.assertEqual(self.popen.call_count, 1)


class TestRHEL(TestLinux):
def setUp(self):
super(self.__class__, self).setUp()
Expand Down Expand Up @@ -316,7 +368,8 @@ def test_install(self):
mock.call(
['service', 'codedeploy-agent', 'stop'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
),
mock.call().communicate()
])
Expand All @@ -341,13 +394,34 @@ def test_uninstall(self):
mock.call(
['service', 'codedeploy-agent', 'stop'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
text=True
),
mock.call().communicate()
])
self.check_call.assert_has_calls([
mock.call(['yum', '-y', 'erase', 'codedeploy-agent'])
])

def test_install_service_not_found(self):
process = mock.MagicMock()
process.communicate.return_value = (
'', 'Redirecting to /bin/systemctl stop codedeploy-agent.service'
)
process.returncode = 1
self.popen.return_value = process
self.rhel.install(self.params)

def test_uninstall_service_not_found(self):
process = mock.MagicMock()
process.communicate.return_value = (
'', 'Redirecting to /bin/systemctl stop codedeploy-agent.service'
)
process.returncode = 1
self.popen.return_value = process
self.rhel.uninstall(self.params)
self.assertEqual(self.popen.call_count, 1)


if __name__ == "__main__":
unittest.main()