Beispiel #1
0
 def schema_from(yaml_str):
     pickled_yaml = pickle.dumps(yaml.load(yaml_str))
     mocked_open = mock.mock_open(read_data=pickled_yaml)
     with mock.patch('{}.io.open'.format(vdsmapi.__name__),
                     mocked_open,
                     create=True):
         return vdsmapi.Schema.vdsm_api(strict_mode=False)
Beispiel #2
0
 def _schema_from(yaml_str):
     pickled_yaml = pickle.dumps(yaml.load(yaml_str))
     mocked_open = mock.mock_open(read_data=pickled_yaml)
     with mock.patch('{}.io.open'.format(vdsmapi.__name__),
                     mocked_open,
                     create=True):
         return vdsmapi.Schema.vdsm_api(strict_mode=False)
Beispiel #3
0
    def test_supported(self):
        with namedTemporaryDir() as src:
            # A list of 3 file names, where the files are temporary.
            sizes = [os.path.basename(f.name) for f in [
                tempfile.NamedTemporaryFile(
                    dir=src, delete=False
                ) for _ in range(3)
            ]]
            with mock.patch('{}.open'.format(hugepages.__name__),
                            mock.mock_open(read_data='0'),
                            create=True):

                self.assertEqual(set(hugepages.supported(src)), set(sizes))
Beispiel #4
0
    def test_state(self):
        with namedTemporaryDir() as src:
            # A list of 3 file names, where the files are temporary.
            sizes = [os.path.basename(f.name) for f in [
                tempfile.NamedTemporaryFile(
                    dir=src, delete=False
                ) for _ in range(3)
            ]]
            with mock.patch('{}.open'.format(hugepages.__name__),
                            mock.mock_open(read_data='1234'),
                            create=True):

                self.assertEqual(len(hugepages.state(src)), len(sizes))
                for value in hugepages.state(src).values():
                    self.assertEqual(value, _STATE)
Beispiel #5
0
class IPDhclientTest(VdsmTestCase):
    @mock.patch.object(
        dhclient, 'open',
        mock.mock_open(read_data=DHCLIENT_CMDLINE_WITH_HOST_AT_TAIL))
    @mock.patch.object(dhclient, 'pgrep', lambda x: (0, ))
    def test_daemon_cmdline_with_last_arg_as_hostname(self):
        """
        In most cases, the dhclient is executed with a cmdline that locates
        the device name at the last argument. However, an exception has been
        detected with DHCPv6 from ifcfg initscripts, in which the last argument
        is the host name and the device name is placed just before it.
        """
        dhcp_info = dhclient.dhcp_info(devices=(DEVNAME, ))
        expected = {DEVNAME: {dhclient.DHCP4: False, dhclient.DHCP6: True}}
        self.assertEqual(expected, dhcp_info)