示例#1
0
    def start(self):
        # Open the connection to OVS database
        self.ovs_idl = ovsdb.MetadataAgentOvsIdl().start()
        self._load_config()

        # Launch the server that will act as a proxy between the VM's and Nova.
        proxy = metadata_server.UnixDomainMetadataProxy(self.conf)
        proxy.run()

        # Open the connection to OVN SB database.
        self.sb_idl = ovsdb.MetadataAgentOvnSbIdl(
            chassis=self.chassis,
            events=[
                PortBindingChassisCreatedEvent(self),
                PortBindingChassisDeletedEvent(self),
                ChassisCreateEvent(self),
                SbGlobalUpdateEvent(self)
            ]).start()

        # Do the initial sync.
        self.sync()

        # Register the agent with its corresponding Chassis
        self.register_metadata_agent()

        proxy.wait()
示例#2
0
    def test_init_exists_unlink_no_file(self):
        with mock.patch('os.path.isdir') as isdir:
            with mock.patch('os.unlink') as unlink:
                with mock.patch('os.path.exists') as exists:
                    isdir.return_value = True
                    exists.return_value = False
                    unlink.side_effect = OSError

                    agent.UnixDomainMetadataProxy(mock.Mock(), 'chassis1')
                    unlink.assert_called_once_with('/the/path')
示例#3
0
    def test_run(self, ensure_dir, server, handler):
        p = agent.UnixDomainMetadataProxy(self.cfg.CONF, 'chassis1')
        p.run()

        ensure_dir.assert_called_once_with('/the', mode=0o755)
        server.assert_has_calls([
            mock.call('neutron-ovn-metadata-agent'),
            mock.call().start(handler.return_value,
                              '/the/path', workers=0,
                              backlog=128, mode=0o644)]
        )
示例#4
0
    def test_init_exists_unlink_fails_file_still_exists(self):
        with mock.patch('os.path.isdir') as isdir:
            with mock.patch('os.unlink') as unlink:
                with mock.patch('os.path.exists') as exists:
                    isdir.return_value = True
                    exists.return_value = True
                    unlink.side_effect = OSError

                    with testtools.ExpectedException(OSError):
                        agent.UnixDomainMetadataProxy(mock.Mock(), 'chassis1')
                    unlink.assert_called_once_with('/the/path')
示例#5
0
文件: agent.py 项目: stackhpc/neutron
    def start(self):
        # Open the connection to OVS database
        self.ovs_idl = ovsdb.MetadataAgentOvsIdl().start()
        self._load_config()

        # Launch the server that will act as a proxy between the VM's and Nova.
        proxy = metadata_server.UnixDomainMetadataProxy(
            self.conf, self.chassis)
        proxy.run()

        tables = ('Encap', 'Port_Binding', 'Datapath_Binding', 'SB_Global',
                  'Chassis')
        events = (PortBindingChassisCreatedEvent(self),
                  PortBindingChassisDeletedEvent(self),
                  SbGlobalUpdateEvent(self))

        # TODO(lucasagomes): Remove this in the future. Try to register
        # the Chassis_Private table, if not present, fallback to the normal
        # Chassis table.
        # Open the connection to OVN SB database.
        self.has_chassis_private = False
        self._post_fork_event.clear()
        try:
            self.sb_idl = ovsdb.MetadataAgentOvnSbIdl(
                chassis=self.chassis,
                tables=tables + ('Chassis_Private', ),
                events=events + (ChassisPrivateCreateEvent(self), )).start()
            self.has_chassis_private = True
        except AssertionError:
            self.sb_idl = ovsdb.MetadataAgentOvnSbIdl(
                chassis=self.chassis,
                tables=tables,
                events=events + (ChassisCreateEvent(self), )).start()

        # Now IDL connections can be safely used.
        self._post_fork_event.set()

        # Do the initial sync.
        self.sync()

        # Register the agent with its corresponding Chassis
        self.register_metadata_agent()

        proxy.wait()
示例#6
0
 def test_init_exists(self):
     with mock.patch('os.path.isdir') as isdir:
         with mock.patch('os.unlink') as unlink:
             isdir.return_value = True
             agent.UnixDomainMetadataProxy(mock.Mock(), 'chassis1')
             unlink.assert_called_once_with('/the/path')
示例#7
0
 def test_init_doesnot_exists(self, ensure_dir):
     agent.UnixDomainMetadataProxy(mock.Mock(), 'chassis1')
     ensure_dir.assert_called_once_with('/the', mode=0o755)