~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/tests/functional/agent/linux/test_keepalived.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#    License for the specific language governing permissions and limitations
14
14
#    under the License.
15
15
 
16
 
from oslo.config import cfg
 
16
from oslo_config import cfg
17
17
 
18
 
from neutron.agent.common import config
19
18
from neutron.agent.linux import external_process
20
19
from neutron.agent.linux import keepalived
21
 
from neutron.openstack.common import log as logging
22
 
from neutron.tests.functional import base as functional_base
 
20
from neutron.agent.linux import utils
 
21
from neutron.tests import base
23
22
from neutron.tests.unit.agent.linux import test_keepalived
24
23
 
25
 
LOG = logging.getLogger(__name__)
26
 
 
27
 
 
28
 
class KeepalivedManagerTestCase(functional_base.BaseSudoTestCase,
 
24
 
 
25
class KeepalivedManagerTestCase(base.BaseTestCase,
29
26
                                test_keepalived.KeepalivedConfBaseMixin):
 
27
 
30
28
    def setUp(self):
31
29
        super(KeepalivedManagerTestCase, self).setUp()
32
 
        self.check_sudo_enabled()
33
 
        self._configure()
 
30
        cfg.CONF.set_override('check_child_processes_interval', 1, 'AGENT')
34
31
 
35
 
    def _configure(self):
36
 
        cfg.CONF.set_override('debug', False)
37
 
        config.setup_logging()
 
32
        self.expected_config = self._get_config()
 
33
        self.process_monitor = external_process.ProcessMonitor(cfg.CONF,
 
34
                                                               'router')
 
35
        self.manager = keepalived.KeepalivedManager(
 
36
            'router1', self.expected_config, conf_path=cfg.CONF.state_path,
 
37
            process_monitor=self.process_monitor)
 
38
        self.addCleanup(self.manager.get_process().disable)
 
39
        self.addCleanup(self.process_monitor.stop)
38
40
 
39
41
    def test_keepalived_spawn(self):
40
 
        expected_config = self._get_config()
41
 
        manager = keepalived.KeepalivedManager('router1', expected_config,
42
 
                                               conf_path=cfg.CONF.state_path,
43
 
                                               root_helper=self.root_helper)
44
 
        self.addCleanup(manager.disable)
45
 
 
46
 
        manager.spawn()
 
42
        self.manager.spawn()
47
43
        process = external_process.ProcessManager(
48
44
            cfg.CONF,
49
45
            'router1',
50
 
            self.root_helper,
51
46
            namespace=None,
52
47
            pids_path=cfg.CONF.state_path)
53
48
        self.assertTrue(process.active)
54
49
 
55
 
        config_path = manager._get_full_config_file_path('keepalived.conf')
56
 
        with open(config_path, 'r') as config_file:
57
 
            config_contents = config_file.read()
58
 
        self.assertEqual(expected_config.get_config_str(), config_contents)
 
50
        self.assertEqual(self.expected_config.get_config_str(),
 
51
                         self.manager.get_conf_on_disk())
 
52
 
 
53
    def test_keepalived_respawns(self):
 
54
        self.manager.spawn()
 
55
        process = self.manager.get_process()
 
56
        self.assertTrue(process.active)
 
57
 
 
58
        process.disable(sig='15')
 
59
 
 
60
        utils.wait_until_true(
 
61
            lambda: process.active,
 
62
            timeout=5,
 
63
            sleep=0.01,
 
64
            exception=RuntimeError(_("Keepalived didn't respawn")))