Nir Soffer has posted comments on this change.
Change subject: utils: add CommandStream class
......................................................................
Patch Set 7:
(2 comments)
https://gerrit.ovirt.org/#/c/33909/7/tests/utilsTests.py
File tests/utilsTests.py:
Line 770:
Line 771: def _startCommand(self, command):
Line 772: return cpopen.CPopen(command)
Line 773:
Line 774: @permutations((('stdout',), ('stderr',)))
Lets put the command and cb spec here:
@permutations([
# command, recv_out, recv_err
(["echo", "-n", "%s"], True, False),
(["sh", "-c", 'echo -n "%s" >&2'],
False, True),
])
def test_receive(self, cmd, recv_out, recv_err):
So the code is more generic, and we don't need error handling for unsupported
output:
cmd[-1] = cmd[-1] % text
c = self._startCommand(cmd)
p = utils.CommandStream(c,
recv_data if recv_out else self.assertUnexpectedCall,
recv_data if recv_err else self.assertUnexpectedCall)
And later we can easily add more tests, for example, receiving multiple lines,
large amount of data, no data, without changing the code.
Line 775: def test_receive(self, output):
Line 776: text = bytes("Hello World")
Line 777: received = bytearray()
Line 778:
Line 797:
Line 798: self.assertEqual(retcode, 0)
Line 799: self.assertEqual(text, received)
Line 800:
Line 801: @permutations((('stdout',), ('stderr',)))
Same as for test_receive
Line 802: def test_write(self, output):
Line 803: text = "Hello World"
Line 804: received = bytearray()
Line 805:
--
To view, visit
https://gerrit.ovirt.org/33909
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Ie015368bb9c5992e5c73a149277c59fc4ffbd570
Gerrit-PatchSet: 7
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce(a)redhat.com>
Gerrit-Reviewer: Adam Litke <alitke(a)redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken(a)redhat.com>
Gerrit-Reviewer: Federico Simoncelli <fsimonce(a)redhat.com>
Gerrit-Reviewer: Francesco Romani <fromani(a)redhat.com>
Gerrit-Reviewer: Nir Soffer <nsoffer(a)redhat.com>
Gerrit-Reviewer: Piotr Kliczewski <piotr.kliczewski(a)gmail.com>
Gerrit-Reviewer: Saggi Mizrahi <smizrahi(a)redhat.com>
Gerrit-Reviewer: Shahar Havivi <shavivi(a)redhat.com>
Gerrit-Reviewer: automation(a)ovirt.org
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes