コード例 #1
0
    def test_detect_protocol_by_file(self, distro_name, distro_version, 
                                     distro_full_name, _):
        distro = get_distro(distro_name, distro_version, distro_full_name)
        protocol_util = distro.protocol_util

        protocol_util._detect_wire_protocol = Mock()
        protocol_util._detect_metadata_protocol = Mock()

        tag_file = os.path.join(self.tmp_dir, TAG_FILE_NAME)

        #Test tag file doesn't exist
        protocol_util.detect_protocol_by_file()
        protocol_util._detect_wire_protocol.assert_any_call()
        protocol_util._detect_metadata_protocol.assert_not_called()

        #Test tag file exists
        protocol_util.protocol = None
        protocol_util._detect_wire_protocol.reset_mock()
        protocol_util._detect_metadata_protocol.reset_mock()
        with open(tag_file, "w+") as tag_fd:
            tag_fd.write("")

        protocol_util.detect_protocol_by_file()
        protocol_util._detect_metadata_protocol.assert_any_call()
        protocol_util._detect_wire_protocol.assert_not_called()
コード例 #2
0
    def test_detect_protocol_by_file(self, distro_name, distro_version,
                                     distro_full_name, _):
        distro = get_distro(distro_name, distro_version, distro_full_name)
        protocol_util = distro.protocol_util

        protocol_util._detect_wire_protocol = Mock()
        protocol_util._detect_metadata_protocol = Mock()

        tag_file = os.path.join(self.tmp_dir, TAG_FILE_NAME)

        #Test tag file doesn't exist
        protocol_util.detect_protocol_by_file()
        protocol_util._detect_wire_protocol.assert_any_call()
        protocol_util._detect_metadata_protocol.assert_not_called()

        #Test tag file exists
        protocol_util.protocol = None
        protocol_util._detect_wire_protocol.reset_mock()
        protocol_util._detect_metadata_protocol.reset_mock()
        with open(tag_file, "w+") as tag_fd:
            tag_fd.write("")

        protocol_util.detect_protocol_by_file()
        protocol_util._detect_metadata_protocol.assert_any_call()
        protocol_util._detect_wire_protocol.assert_not_called()
コード例 #3
0
    def test_detect_protocol(self, distro_name, distro_version, distro_full_name, 
                             WireProtocol, MetadataProtocol, _, *distro_args):

        WireProtocol.return_value = MagicMock()
        MetadataProtocol.return_value = MagicMock()
        
        distro = get_distro(distro_name, distro_version, distro_full_name)
        distro.dhcp_handler = MagicMock()
        distro.dhcp_handler.endpoint = "foo.bar"

        #Test wire protocol is available
        protocol = distro.protocol_util.detect_protocol()
        self.assertEquals(WireProtocol.return_value, protocol)

        #Test wire protocol is not available
        distro.protocol_util.protocol = None
        WireProtocol.side_effect = ProtocolError()

        protocol = distro.protocol_util.detect_protocol()
        self.assertEquals(MetadataProtocol.return_value, protocol)

        #Test no protocol is available
        distro.protocol_util.protocol = None
        WireProtocol.side_effect = ProtocolError()
        MetadataProtocol.side_effect = ProtocolError()
        self.assertRaises(ProtocolError, distro.protocol_util.detect_protocol)
コード例 #4
0
    def test_detect_protocol(self, distro_name, distro_version,
                             distro_full_name, WireProtocol, MetadataProtocol,
                             _, *distro_args):

        WireProtocol.return_value = MagicMock()
        MetadataProtocol.return_value = MagicMock()

        distro = get_distro(distro_name, distro_version, distro_full_name)
        distro.dhcp_handler = MagicMock()
        distro.dhcp_handler.endpoint = "foo.bar"

        #Test wire protocol is available
        protocol = distro.protocol_util.detect_protocol()
        self.assertEquals(WireProtocol.return_value, protocol)

        #Test wire protocol is not available
        distro.protocol_util.protocol = None
        WireProtocol.side_effect = ProtocolError()

        protocol = distro.protocol_util.detect_protocol()
        self.assertEquals(MetadataProtocol.return_value, protocol)

        #Test no protocol is available
        distro.protocol_util.protocol = None
        WireProtocol.side_effect = ProtocolError()
        MetadataProtocol.side_effect = ProtocolError()
        self.assertRaises(ProtocolError, distro.protocol_util.detect_protocol)
コード例 #5
0
    def test_daemon_restart(self, mock_sleep):
        distro = get_distro()
        mock_daemon = Mock(side_effect=MockDaemonCall(distro.daemon_handler, 2))
        distro.daemon_handler.daemon = mock_daemon
        distro.daemon_handler.check_pid = Mock()
        distro.daemon_handler.run()

        mock_sleep.assert_any_call(15)
        self.assertEquals(2, distro.daemon_handler.daemon.call_count)
コード例 #6
0
    def test_check_pid(self, mock_exit, mock_conf, mock_sleep):
        distro = get_distro()
        mock_pid_file = os.path.join(self.tmp_dir, "pid")
        mock_conf.get_agent_pid_file_path = Mock(return_value=mock_pid_file)

        distro.daemon_handler.check_pid()
        self.assertTrue(os.path.isfile(mock_pid_file))

        distro.daemon_handler.check_pid()
        mock_exit.assert_any_call(0)
コード例 #7
0
    def test_daemon_restart(self, mock_sleep):
        distro = get_distro()
        mock_daemon = Mock(
            side_effect=MockDaemonCall(distro.daemon_handler, 2))
        distro.daemon_handler.daemon = mock_daemon
        distro.daemon_handler.check_pid = Mock()
        distro.daemon_handler.run()

        mock_sleep.assert_any_call(15)
        self.assertEquals(2, distro.daemon_handler.daemon.call_count)
コード例 #8
0
    def test_check_pid(self, mock_exit, mock_conf, mock_sleep):
        distro = get_distro()
        mock_pid_file = os.path.join(self.tmp_dir, "pid")
        mock_conf.get_agent_pid_file_path = Mock(return_value=mock_pid_file)

        distro.daemon_handler.check_pid()
        self.assertTrue(os.path.isfile(mock_pid_file))

        distro.daemon_handler.check_pid()
        mock_exit.assert_any_call(0)
コード例 #9
0
    def test_provision(self, distro_name, distro_version, distro_full_name):
        distro = get_distro(distro_name, distro_version, distro_full_name)
        distro.osutil = MagicMock()
        distro.osutil.decode_customdata = Mock(return_value="")

        distro.protocol_util.detect_protocol_by_file = MagicMock()
        distro.protocol_util.get_protocol = MagicMock()
        conf.get_dvd_mount_point = Mock(return_value=self.tmp_dir)

        ovfenv_file = os.path.join(self.tmp_dir, OVF_FILE_NAME)
        ovfenv_data = load_data("ovf-env.xml")
        fileutil.write_file(ovfenv_file, ovfenv_data)

        handler = distro.provision_handler
        handler.run()
コード例 #10
0
    def _create_mock(self, test_data, mock_http_get, MockCryptUtil, _):
        """Test enable/disable/unistall of an extension"""
        distro = get_distro()
        
        #Mock protocol to return test data
        mock_http_get.side_effect = test_data.mock_http_get
        MockCryptUtil.side_effect = test_data.mock_crypt_util

        protocol = WireProtocol("foo.bar")
        protocol.detect()
        protocol.report_ext_status = MagicMock()
        protocol.report_vm_status = MagicMock()
        distro.protocol_util.get_protocol = Mock(return_value=protocol)
        
        return distro, protocol
コード例 #11
0
    def test_provision(self, distro_name, distro_version, distro_full_name):
        distro = get_distro(distro_name, distro_version, distro_full_name)
        distro.osutil = MagicMock()
        distro.osutil.decode_customdata = Mock(return_value="")

        distro.protocol_util.detect_protocol_by_file = MagicMock()
        distro.protocol_util.get_protocol = MagicMock()
        conf.get_dvd_mount_point = Mock(return_value=self.tmp_dir)

        ovfenv_file = os.path.join(self.tmp_dir, OVF_FILE_NAME)
        ovfenv_data = load_data("ovf-env.xml")
        fileutil.write_file(ovfenv_file, ovfenv_data)
         
        handler = distro.provision_handler
        handler.run()
コード例 #12
0
    def _create_mock(self, test_data, mock_http_get, MockCryptUtil, _):
        """Test enable/disable/unistall of an extension"""
        distro = get_distro()

        #Mock protocol to return test data
        mock_http_get.side_effect = test_data.mock_http_get
        MockCryptUtil.side_effect = test_data.mock_crypt_util

        protocol = WireProtocol("foo.bar")
        protocol.detect()
        protocol.report_ext_status = MagicMock()
        protocol.report_vm_status = MagicMock()
        distro.protocol_util.get_protocol = Mock(return_value=protocol)

        return distro, protocol
コード例 #13
0
 def __init__(self, verbose):
     """
     Initialize agent running environment.
     """
     self.distro = get_distro();
     self.distro.init_handler.run(verbose)
コード例 #14
0
 def test_distro_loader(self, *distro_args):
     distro = get_distro(*distro_args)
     self.assertNotEquals(None, distro)
     self.assertNotEquals(DefaultDistro, type(distro))