Ejemplo n.º 1
0
 def tearDown(self):
     if os.path.exists(TEMP_PATH):
         self.api.svs.stop()
     try:
         iptables.remove_rule_once('ACCEPT', self.port, 'tcp')
     except:
         pass
Ejemplo n.º 2
0
 def tearDown(self):
     if os.path.exists(TEMP_PATH):
         self.api.svs.stop()
     try:
         iptables.remove_rule_once('ACCEPT', self.port, 'tcp')
     except:
         pass
Ejemplo n.º 3
0
	def delete_listener(self, port=None, protocol=None):
		''' Delete listen section(s) by port (and)or protocol '''

		ln = haproxy.naming('listen', protocol, port)
		if not self.cfg.sections(ln):
			raise exceptions.NotFound('Listen `%s` not found can`t remove it' % ln)
		try:
			default_backend = self.cfg.listener[ln]['default_backend']
		except:
			default_backend = None

		for path in self.cfg.sections(ln):
			del self.cfg['listen'][ln]
			LOG.debug('HAProxyAPI.delete_listener: removed listener `%s`' % ln)

		if default_backend:
			has_ref = False
			for ln in self.cfg.listener:
				try:
					if self.cfg.listener[ln]['default_backend'] == default_backend:
						has_ref = True
						break
				except:
					pass
			if not has_ref:
				#it not used in other section, so will be deleting
				del self.cfg.backends[default_backend]

		try:
			iptables.remove_rule_once('ACCEPT', port, protocol if protocol != 'http' else 'tcp')
		except Exception, e:
			raise exceptions.NotFound(e)
Ejemplo n.º 4
0
    def test_remove_server(self):
        self.api.create_listener(protocol=self.protocol,
                                 port=self.port,
                                 server_port=self.server_port,
                                 server_protocol=self.server_protocol,
                                 backend=self.backend)
        self.api.add_server(ipaddr=self.ipaddr, backend=self.backend)

        self.assertEqual(
            self.api.cfg.backends['scalr:backend:%s:%s:%s' %
                                  (self.backend, self.server_protocol,
                                   self.server_port)]['server'][
                                       self.ipaddr.replace('.', '-')], {
                                           'address': self.ipaddr,
                                           'port': str(self.server_port),
                                           'check': True
                                       })

        self.api.remove_server(ipaddr=self.ipaddr, backend=self.backend)

        try:
            server = self.api.cfg.backends['scalr:backend:%s:%s:%s' %
                                           (self.backend, self.protocol,
                                            self.port)]['server'][
                                                self.ipaddr.replace('.', '-')]
        except:
            server = None
        self.assertIsNone(server)

        self.api.add_server(ipaddr=self.ipaddr, backend=self.backend)
        self.api.add_server(ipaddr='10.168.58.46', backend=self.backend)

        self.assertEqual(
            self.api.cfg.backends['scalr:backend:%s:%s:%s' %
                                  (self.backend, self.server_protocol,
                                   self.server_port)]['server'][
                                       self.ipaddr.replace('.', '-')], {
                                           'address': self.ipaddr,
                                           'port': str(self.server_port),
                                           'check': True
                                       })

        self.assertEqual(
            self.api.cfg.backends['scalr:backend:%s:%s:%s' %
                                  (self.backend, self.server_protocol,
                                   self.server_port)]['server']
            ['10-168-58-46'], {
                'address': '10.168.58.46',
                'port': str(self.server_port),
                'check': True
            })

        for srv in self.api.list_servers(backend=self.backend):
            self.api.remove_server(ipaddr=srv, backend=self.backend)

        try:
            server = self.api.cfg.backends['scalr:backend:%s:%s:%s' %
                                           (self.backend, self.protocol,
                                            self.port)]['server'][
                                                self.ipaddr.replace('.', '-')]

            server = self.api.cfg.backends[
                'scalr:backend:%s:%s:%s' %
                (self.backend, self.protocol,
                 self.port)]['server']['10-168-58-46']
        except:
            server = None
        self.assertIsNone(server)

        self.api.create_listener(protocol=self.protocol,
                                 port=2288,
                                 server_port=self.server_port,
                                 server_protocol=self.server_protocol,
                                 backend='role:4321')

        self.api.add_server(ipaddr=self.ipaddr)
        self.api.add_server(ipaddr='10.168.58.46')

        self.assertEqual(
            self.api.cfg.backends['scalr:backend:%s:%s:%s' %
                                  (self.backend, self.server_protocol,
                                   self.server_port)]['server']
            ['10-168-58-46'], {
                'address': '10.168.58.46',
                'port': str(self.server_port),
                'check': True
            })

        self.assertEqual(
            self.api.cfg.backends['scalr:backend:%s:%s:%s' %
                                  ('role:4321', self.server_protocol,
                                   self.server_port)]['server']
            ['10-168-58-46'], {
                'address': '10.168.58.46',
                'port': str(self.server_port),
                'check': True
            })

        for srv in self.api.list_servers():
            self.api.remove_server(ipaddr=srv)

        try:
            server = self.api.cfg.backends['scalr:backend:%s:%s:%s' %
                                           (self.backend, self.protocol,
                                            self.port)]['server'][
                                                self.ipaddr.replace('.', '-')]

            server = self.api.cfg.backends[
                'scalr:backend:%s:%s:%s' %
                ('role:4321', self.protocol,
                 self.port)]['server']['10-168-58-46']
        except:
            server = None
        self.assertIsNone(server)

        iptables.remove_rule_once('ACCEPT', 2288, 'tcp')
Ejemplo n.º 5
0
    def test_remove_server(self):
        self.api.create_listener(protocol=self.protocol, port=self.port, server_port=self.server_port,
                server_protocol=self.server_protocol, backend=self.backend)
        self.api.add_server(ipaddr=self.ipaddr, backend=self.backend)

        self.assertEqual(self.api.cfg.backends['scalr:backend:%s:%s:%s' % (self.backend,
                self.server_protocol, self.server_port)]['server'][self.ipaddr.replace('.', '-')],
                {'address': self.ipaddr, 'port': str(self.server_port), 'check':True})

        self.api.remove_server(ipaddr=self.ipaddr, backend=self.backend)

        try:
            server = self.api.cfg.backends['scalr:backend:%s:%s:%s' % (self.backend,
            self.protocol, self.port)]['server'][self.ipaddr.replace('.', '-')]
        except:
            server = None
        self.assertIsNone(server)


        self.api.add_server(ipaddr=self.ipaddr, backend=self.backend)
        self.api.add_server(ipaddr='10.168.58.46', backend=self.backend)


        self.assertEqual(self.api.cfg.backends['scalr:backend:%s:%s:%s' % (self.backend,
                self.server_protocol, self.server_port)]['server'][self.ipaddr.replace('.', '-')],
                {'address': self.ipaddr, 'port': str(self.server_port), 'check':True})

        self.assertEqual(self.api.cfg.backends['scalr:backend:%s:%s:%s' % (self.backend,
                self.server_protocol, self.server_port)]['server']['10-168-58-46'],
                {'address': '10.168.58.46', 'port': str(self.server_port), 'check':True})

        for srv in self.api.list_servers(backend=self.backend):
            self.api.remove_server(ipaddr=srv, backend=self.backend)

        try:
            server = self.api.cfg.backends['scalr:backend:%s:%s:%s' % (self.backend,
                    self.protocol, self.port)]['server'][self.ipaddr.replace('.', '-')]

            server = self.api.cfg.backends['scalr:backend:%s:%s:%s' % (
                    self.backend, self.protocol, self.port)]['server']['10-168-58-46']
        except:
            server = None
        self.assertIsNone(server)

        self.api.create_listener(protocol=self.protocol, port=2288, server_port=self.server_port,
                        server_protocol=self.server_protocol, backend='role:4321')

        self.api.add_server(ipaddr=self.ipaddr)
        self.api.add_server(ipaddr='10.168.58.46')

        self.assertEqual(self.api.cfg.backends['scalr:backend:%s:%s:%s' % (self.backend,
                self.server_protocol, self.server_port)]['server']['10-168-58-46'],
                {'address': '10.168.58.46', 'port': str(self.server_port), 'check':True})

        self.assertEqual(self.api.cfg.backends['scalr:backend:%s:%s:%s' % ('role:4321',
                self.server_protocol, self.server_port)]['server']['10-168-58-46'],
                {'address': '10.168.58.46', 'port': str(self.server_port), 'check':True})


        for srv in self.api.list_servers():
            self.api.remove_server(ipaddr=srv)

        try:
            server = self.api.cfg.backends['scalr:backend:%s:%s:%s' % (self.backend,
                    self.protocol, self.port)]['server'][self.ipaddr.replace('.', '-')]

            server = self.api.cfg.backends['scalr:backend:%s:%s:%s' % ('role:4321',
                    self.protocol, self.port)]['server']['10-168-58-46']
        except:
            server = None
        self.assertIsNone(server)

        iptables.remove_rule_once('ACCEPT', 2288, 'tcp')