Exemplo n.º 1
0
 def test_create_no_xml_too_many_attempts(self):
     """RuntimeError is raised if too many attempt to create a network are made."""
     hypervisor = mock.Mock()
     hypervisor.listNetworks.return_value = []
     hypervisor.networkCreateXML.side_effect = libvirt.libvirtError('BOOM')
     with self.assertRaises(RuntimeError) as error:
         network.create(hypervisor, 'foo', {}, max_attempts=1)
         self.assertEqual(str(error), "Too many attempts (1) to get a valid IP address.")
Exemplo n.º 2
0
 def test_create_no_xml(self):
     """Default XML configuration is used if not provided."""
     expected = """<network><forward mode="nat" /><name>foo</name><uuid>foo</uuid>""" +\
                """<bridge name="virbr-foo" /></network>"""
     hypervisor = mock.Mock()
     hypervisor.listNetworks.return_value = []
     network.create(hypervisor, 'foo', {})
     results = hypervisor.networkCreateXML.call_args_list[0][0][0]
     self.assertEqual(results, expected, compare(results, expected))
Exemplo n.º 3
0
 def test_create_xml_error(self):
     """NETWORK RuntimeError is raised in case of creation error."""
     xml = """<network><forward mode="nat"/><ip address="192.168.1.1" netmask="255.255.255.0">""" + \
           """<dhcp><range end="192.168.1.128" start="192.168.1.2"/></dhcp></ip></network>"""
     hypervisor = mock.Mock()
     hypervisor.listNetworks.return_value = []
     hypervisor.networkCreateXML.side_effect = libvirt.libvirtError('BOOM')
     with mock.patch('see.context.resources.network.open', mock.mock_open(read_data=xml), create=True):
         with self.assertRaises(RuntimeError) as error:
             network.create(hypervisor, 'foo', {'configuration': '/foo', 'ip_autodiscovery': False})
             self.assertEqual(str(error), "Unable to create new network: BOOM.")
Exemplo n.º 4
0
 def test_create_xml(self):
     """NETWORK Provided XML is used."""
     xml = """<network><forward mode="nat"/><ip address="192.168.1.1" netmask="255.255.255.0">""" + \
           """<dhcp><range end="192.168.1.128" start="192.168.1.2"/></dhcp></ip></network>"""
     expected = """<network><forward mode="nat" /><ip address="192.168.1.1" netmask="255.255.255.0">""" + \
         """<dhcp><range end="192.168.1.128" start="192.168.1.2" /></dhcp></ip>""" + \
         """<name>foo</name><uuid>foo</uuid><bridge name="virbr-foo" /></network>"""
     hypervisor = mock.Mock()
     hypervisor.listNetworks.return_value = []
     with mock.patch('see.context.resources.network.open', mock.mock_open(read_data=xml), create=True):
         network.create(hypervisor, 'foo', {'configuration': '/foo', 'ip_autodiscovery': False})
     results = hypervisor.networkCreateXML.call_args_list[0][0][0]
     self.assertEqual(results, expected, compare(results, expected))
Exemplo n.º 5
0
    def test_create_too_many_attempts(self):
        """RuntimeError is raised if too many fails to create a network."""
        network.MAX_ATTEMPTS = 1
        hypervisor = mock.Mock()
        hypervisor.listNetworks.return_value = []
        hypervisor.networkCreateXML.side_effect = libvirt.libvirtError('BOOM')
        xml = '<foo>bar<foo/>'
        configuration = {'configuration': 'baz'}

        with mock.patch('see.context.resources.network.open',
                        mock.mock_open(read_data=xml), create=True):
            with mock.patch('see.context.resources.network.network_xml'):
                with self.assertRaises(RuntimeError) as error:
                    network.create(hypervisor, 'foo', configuration)
                    self.assertEqual(str(error),
                                     "Exceeded Attempts (1) to get IP address.")
Exemplo n.º 6
0
 def test_create_xml(self):
     """Provided XML is used."""
     xml = """<network><forward mode="nat"/><ip address="192.168.1.1" netmask="255.255.255.0">""" + \
           """<dhcp><range end="192.168.1.128" start="192.168.1.2"/></dhcp></ip></network>"""
     expected = """<network><forward mode="nat" /><ip address="192.168.1.1" netmask="255.255.255.0">""" + \
         """<dhcp><range end="192.168.1.128" start="192.168.1.2" /></dhcp></ip>""" + \
         """<name>foo</name><uuid>foo</uuid><bridge name="virbr-foo" /></network>"""
     hypervisor = mock.Mock()
     hypervisor.listNetworks.return_value = []
     with mock.patch('see.context.resources.network.open',
                     mock.mock_open(read_data=xml),
                     create=True):
         network.create(hypervisor, 'foo', {
             'configuration': '/foo',
             'ip_autodiscovery': False
         })
     results = hypervisor.networkCreateXML.call_args_list[0][0][0]
     self.assertEqual(results, expected, compare(results, expected))
Exemplo n.º 7
0
    def _retrieve_network_name(self, configuration):
        network_name = None

        if configuration is not None:
            new_network = network.create(self._hypervisor, self.identifier,
                                         configuration)
            network_name = new_network.name()

        return network_name
Exemplo n.º 8
0
    def test_create_too_many_attempts(self):
        """RuntimeError is raised if too many fails to create a network."""
        xml = '<network><forward mode="nat"/></network>'
        network.MAX_ATTEMPTS = 3
        hypervisor = mock.Mock()
        hypervisor.listNetworks.return_value = []
        hypervisor.networkCreateXML.side_effect = libvirt.libvirtError('BOOM')
        configuration = {'configuration': 'bar',
                         'dynamic_address': {'ipv4': '10.0.0.0',
                                             'prefix': 16,
                                             'subnet_prefix': 24}}

        with mock.patch('see.context.resources.network.open',
                        mock.mock_open(read_data=xml), create=True):
            try:
                network.create(hypervisor, 'foo', configuration)
            except RuntimeError as error:
                self.assertEqual(str(error),
                                 "Exceeded attempts (3) to get IP address.")
Exemplo n.º 9
0
Arquivo: lxc.py Projeto: zdzhjx/see
    def _initialize(self):
        """Initializes libvirt resources."""
        network_name = None
        url = 'hypervisor' in self.configuration and self.configuration['hypervisor'] or 'lxc:///'

        self._hypervisor = libvirt.open(url)
        if 'network' in self.configuration:
            self._network = network.create(self._hypervisor, self.identifier, self.configuration['network'])
            network_name = self._network.name()
        self._domain = domain_create(self._hypervisor, self.identifier, self.configuration['domain'],
                                     network_name=network_name)
Exemplo n.º 10
0
    def test_create_too_many_attempts(self):
        """NETWORK RuntimeError is raised if too many fails to create a network."""
        xml = '<network><forward mode="nat"/></network>'
        network.MAX_ATTEMPTS = 3
        hypervisor = mock.Mock()
        hypervisor.listNetworks.return_value = []
        hypervisor.networkCreateXML.side_effect = libvirt.libvirtError('BOOM')
        configuration = {'configuration': 'bar',
                         'dynamic_address': {'ipv4': '10.0.0.0',
                                             'prefix': 16,
                                             'subnet_prefix': 24}}

        with mock.patch('see.context.resources.network.open',
                        mock.mock_open(read_data=xml), create=True):
            try:
                network.create(hypervisor, 'foo', configuration)
            except RuntimeError as error:
                self.assertEqual(
                    error.args,
                    ("Exceeded failed attempts (3) to get IP address.",
                     "Last error: BOOM"))
Exemplo n.º 11
0
    def _initialize(self):
        """Initializes libvirt resources."""
        network_name = None
        url = "hypervisor" in self.configuration and self.configuration["hypervisor"] or "lxc:///"

        self._hypervisor = libvirt.open(url)
        if "network" in self.configuration:
            self._network = network.create(self._hypervisor, self.identifier, self.configuration["network"])
            network_name = self._network.name()
        self._domain = domain_create(
            self._hypervisor, self.identifier, self.configuration["domain"], network_name=network_name
        )
Exemplo n.º 12
0
    def _initialize(self):
        """Initializes libvirt resources."""
        network_name = None
        url = 'hypervisor' in self.configuration and self.configuration[
            'hypervisor'] or 'lxc:///'

        self._hypervisor = libvirt.open(url)
        if 'network' in self.configuration:
            self._network = network.create(self._hypervisor, self.identifier,
                                           self.configuration['network'])
            network_name = self._network.name()
        self._domain = domain_create(self._hypervisor,
                                     self.identifier,
                                     self.configuration['domain'],
                                     network_name=network_name)
Exemplo n.º 13
0
    def _initialize(self):
        """Initializes libvirt resources."""
        network_name = None
        url = 'hypervisor' in self.configuration and self.configuration['hypervisor'] or 'qemu:///system'

        self._hypervisor = libvirt.open(url)
        if 'clone' in self.configuration['disk']:
            disk_path = self._clone_disk()
        else:
            disk_path = self.configuration['disk']['image']
        if 'network' in self.configuration:
            self._network = network.create(self._hypervisor, self.identifier, self.configuration['network'])
            network_name = self._network.name()

        self._domain = domain_create(self._hypervisor, self.identifier, self.configuration['domain'],
                                     disk_path, network_name=network_name)
Exemplo n.º 14
0
    def allocate(self):
        """Initializes libvirt resources."""
        network_name = None

        self._hypervisor = libvirt.open(
            self.configuration.get('hypervisor', 'lxc:///'))

        if 'network' in self.configuration:
            self._network = network.create(self._hypervisor, self.identifier,
                                           self.configuration['network'])
            network_name = self._network.name()

        self._domain = domain_create(self._hypervisor, self.identifier,
                                     self.configuration['domain'],
                                     network_name=network_name)
        if self._network is None:
            self._network = network.lookup(self._domain)
Exemplo n.º 15
0
Arquivo: qemu.py Projeto: noxdafox/see
    def allocate(self):
        """Initializes libvirt resources."""
        network_name = None

        self._hypervisor = libvirt.open(self.configuration.get("hypervisor", "qemu:///system"))

        self._storage_pool = self._retrieve_pool()

        if "network" in self.configuration:
            self._network = network.create(self._hypervisor, self.identifier, self.configuration["network"])
            network_name = self._network.name()

        disk_path = self._retrieve_disk_path()

        self._domain = domain_create(
            self._hypervisor, self.identifier, self.configuration["domain"], disk_path, network_name=network_name
        )

        if self._network is None:
            self._network = network.lookup(self._domain)
Exemplo n.º 16
0
    def _initialize(self):
        """Initializes libvirt resources."""
        network_name = None
        url = 'hypervisor' in self.configuration and self.configuration[
            'hypervisor'] or 'qemu:///system'

        self._hypervisor = libvirt.open(url)
        if 'clone' in self.configuration['disk']:
            disk_path = self._clone_disk()
        else:
            disk_path = self.configuration['disk']['image']
        if 'network' in self.configuration:
            self._network = network.create(self._hypervisor, self.identifier,
                                           self.configuration['network'])
            network_name = self._network.name()

        self._domain = domain_create(self._hypervisor,
                                     self.identifier,
                                     self.configuration['domain'],
                                     disk_path,
                                     network_name=network_name)
Exemplo n.º 17
0
    def allocate(self):
        """Initializes libvirt resources."""
        network_name = None

        self._hypervisor = libvirt.open(
            self.configuration.get('hypervisor', 'qemu:///system'))

        self._storage_pool = self._retrieve_pool()

        if 'network' in self.configuration:
            self._network = network.create(self._hypervisor, self.identifier,
                                           self.configuration['network'])
            network_name = self._network.name()

        disk_path = self._retrieve_disk_path()

        self._domain = domain_create(self._hypervisor,
                                     self.identifier,
                                     self.configuration['domain'],
                                     disk_path,
                                     network_name=network_name)

        if self._network is None:
            self._network = network.lookup(self._domain)
Exemplo n.º 18
0
 def test_create_empty_config(self):
     """NETWORK RuntimeError raised if empty configuration."""
     hypervisor = mock.Mock()
     with self.assertRaises(RuntimeError):
         network.create(hypervisor, 'foo', {})