Use check_output

The await function is essentially a non-standard check_output call.
Let's use standard calls to increase maintainability.

Change-Id: I2c25e1cd7122791fcaa86b46bd801e661471bc9e
This commit is contained in:
Ian Wienand 2017-05-09 15:49:39 +10:00
parent 59a1fc6546
commit 6f90daca7f
2 changed files with 3 additions and 24 deletions

View File

@ -12,12 +12,12 @@
import fixtures import fixtures
import logging import logging
import subprocess
import testtools import testtools
from diskimage_builder import block_device from diskimage_builder import block_device
from diskimage_builder.block_device.level0 import localloop from diskimage_builder.block_device.level0 import localloop
from diskimage_builder.logging_config import setup from diskimage_builder.logging_config import setup
from diskimage_builder import utils as dib_utils
# Setup Logging # Setup Logging
@ -80,8 +80,7 @@ class TestBlockDevice(testtools.TestCase):
lb_dev = bd.state['image0']['device'] lb_dev = bd.state['image0']['device']
# partprobe loopback so we can get partition info # partprobe loopback so we can get partition info
args = ['sudo', 'partprobe', lb_dev] args = ['sudo', 'partprobe', lb_dev]
subp, rval = dib_utils.await_popen_cmd(logging, args) logging.info("Call: %s" % args)
self.assertEqual(0, rval) subprocess.check_call(args)
bd.cmd_cleanup() bd.cmd_cleanup()
self._assert_loopbacks_cleaned(bd) self._assert_loopbacks_cleaned(bd)

View File

@ -1,20 +0,0 @@
# 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 subprocess
def await_popen_cmd(logger, *args, **kwargs):
if logger is not None:
logger.debug("Running command: %s", args)
subproc = subprocess.Popen(*args, **kwargs)
return subproc, subproc.wait()