blob: b232eca2c4b15e346451ef83ee7080228b00dc6f [file] [log] [blame]
# -*- coding: utf-8 -*-
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""This module tests helpers in devserver_wrapper."""
from __future__ import print_function
import sys
from chromite.lib import cros_test_lib
from chromite.lib import dev_server_wrapper
from chromite.lib import partial_mock
assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
pytestmark = cros_test_lib.pytestmark_inside_only
# pylint: disable=protected-access
class TestXbuddyHelpers(cros_test_lib.MockTempDirTestCase):
"""Test xbuddy helper functions."""
class TestGetIPv4Address(cros_test_lib.RunCommandTestCase):
"""Tests the GetIPv4Address function."""
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state \
DOWN qlen 1000
link/ether cc:cc:cc:cc:cc:cc brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP \
qlen 1000
link/ether dd:dd:dd:dd:dd:dd brd ff:ff:ff:ff:ff:ff
inet brd scope global eth1
inet6 cdef:0:cdef:cdef:cdef:cdef:cdef:cdef/64 scope global dynamic
valid_lft 2592000sec preferred_lft 604800sec
def testGetIPv4AddressParseResult(self):
"""Verifies we can parse the output and get correct IP address."""
self.rc.AddCmdResult(partial_mock.In('ip'), output=self.IP_GLOBAL_OUTPUT)
self.assertEqual(dev_server_wrapper.GetIPv4Address(), '')
def testGetIPv4Address(self):
"""Tests that correct shell commmand is called."""
dev_server_wrapper.GetIPv4Address(global_ip=False, dev='eth0')
['ip', 'addr', 'show', 'scope', 'host', 'dev', 'eth0'])
self.rc.assertCommandContains(['ip', 'addr', 'show', 'scope', 'global'])