Esempio n. 1
0
 def test_no_use_sudo_in_snap(self):
     patch_call_and_check = self.patch(ipaddr_module, "call_and_check")
     patch_call_and_check.return_value = json.dumps(
         {"networks": SAMPLE_LXD_NETWORKS})
     self.patch(ipaddr_module, "running_in_snap").return_value = True
     get_ip_addr()
     patch_call_and_check.assert_called_once_with(
         [get_resources_bin_path()])
Esempio n. 2
0
 def test_get_ip_addr_calls_methods(self):
     self.patch(ipaddr_module, "running_in_snap").return_value = False
     patch_call_and_check = self.patch(ipaddr_module, "call_and_check")
     patch_call_and_check.return_value = json.dumps(
         {"networks": SAMPLE_LXD_NETWORKS})
     # all interfaces from binary output are included in result
     self.assertCountEqual(SAMPLE_LXD_NETWORKS, get_ip_addr())
     patch_call_and_check.assert_called_once_with(
         ["sudo", get_resources_bin_path()])
Esempio n. 3
0
 def test_get_ip_addr_calls_methods(self):
     patch_call_and_check = self.patch(ipaddr_module, "call_and_check")
     patch_call_and_check.return_value = json.dumps(
         {"networks": SAMPLE_LXD_NETWORKS})
     # all interfaces from binary output are included in result
     self.assertCountEqual(SAMPLE_LXD_NETWORKS, get_ip_addr())
     self.assertThat(
         patch_call_and_check,
         MockCalledOnceWith([get_resources_bin_path()]),
     )
Esempio n. 4
0
def get_ip_addr():
    """Returns this system's local IP address information as a dictionary.

    :raises:ExternalProcessError: if IP address information could not be
        gathered.
    """
    output = call_and_check([get_resources_bin_path()])
    ifaces = parse_lxd_networks(json.loads(output)["networks"])
    _update_interface_type(ifaces)
    _annotate_with_proc_net_bonding_original_macs(ifaces)
    return ifaces