Exemplo n.º 1
0
    def test_validate_deployment_checks_each_slave_is_connected(
            self,
            slaves_to_validate,
            connected_slaves,
            host_name_to_uid,
            is_valid,
    ):
        def get_host_id(host):
            if host in host_name_to_uid:
                return host_name_to_uid[host]
            else:
                return str(uuid.uuid4())

        self.patch('app.util.network.Network.get_host_id', new=get_host_id)

        deploy_subcommand = DeploySubcommand()
        deploy_subcommand._registered_slave_hostnames = MagicMock(return_value=connected_slaves)
        deploy_subcommand._SLAVE_REGISTRY_TIMEOUT_SEC = 1
        deploy_subcommand._non_registered_slaves = MagicMock()
        validate = partial(deploy_subcommand._validate_successful_deployment, 'master_host_url', slaves_to_validate)
        if not is_valid:
            with self.assertRaises(SystemExit):
                validate()
        else:
            validate()
Exemplo n.º 2
0
    def test_validate_deployment_checks_each_slave_is_connected(
            self,
            slaves_to_validate,
            connected_slaves,
            host_name_to_uid,
            is_valid,
    ):
        def get_host_id(host):
            if host in host_name_to_uid:
                return host_name_to_uid[host]
            else:
                return str(uuid.uuid4())

        self.patch('app.util.network.Network.get_host_id', new=get_host_id)

        deploy_subcommand = DeploySubcommand()
        deploy_subcommand._registered_slave_hostnames = MagicMock(return_value=connected_slaves)
        deploy_subcommand._SLAVE_REGISTRY_TIMEOUT_SEC = 1
        deploy_subcommand._non_registered_slaves = MagicMock()
        validate = partial(deploy_subcommand._validate_successful_deployment, 'master_host_url', slaves_to_validate)
        if not is_valid:
            with self.assertRaises(SystemExit):
                validate()
        else:
            validate()
Exemplo n.º 3
0
 def test_deploy_binaries_and_conf_deploys_both_conf_and_binary_for_remote_host(self):
     mock_DeployTarget = self.patch('app.subcommands.deploy_subcommand.DeployTarget')
     mock_DeployTarget_instance = mock_DeployTarget.return_value
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._deploy_binaries_and_conf(
         'remote_host', 'username', 'exec', '/path/to/exec', '/path/to/conf')
     self.assertTrue(mock_DeployTarget_instance.deploy_binary.called)
     self.assertTrue(mock_DeployTarget_instance.deploy_conf.called)
 def test_deploy_binaries_and_conf_doesnt_deploy_conf_if_localhost_with_same_in_use_conf(self):
     self.patch('os.path.expanduser').return_value = '/home'
     mock_DeployTarget = self.patch('app.subcommands.deploy_subcommand.DeployTarget')
     mock_DeployTarget_instance = mock_DeployTarget.return_value
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._deploy_binaries_and_conf(
         'localhost', 'username', 'exec', '/path/to/exec', '/home/.clusterrunner/clusterrunner.conf')
     self.assertFalse(mock_DeployTarget_instance.deploy_conf.called)
Exemplo n.º 5
0
 def test_deploy_binaries_and_conf_deploys_both_conf_and_binary_for_remote_host(self):
     mock_DeployTarget = self.patch('app.subcommands.deploy_subcommand.DeployTarget')
     mock_DeployTarget_instance = mock_DeployTarget.return_value
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._deploy_binaries_and_conf(
         'remote_host', 'username', 'exec', '/path/to/exec', '/path/to/conf')
     self.assertTrue(mock_DeployTarget_instance.deploy_binary.called)
     self.assertTrue(mock_DeployTarget_instance.deploy_conf.called)
Exemplo n.º 6
0
 def test_deploy_binaries_and_conf_deploys_conf_if_localhost_with_diff_in_use_conf(
         self):
     self.patch('os.path.expanduser').return_value = '/home'
     mock_DeployTarget = self.patch(
         'app.subcommands.deploy_subcommand.DeployTarget')
     mock_DeployTarget_instance = mock_DeployTarget.return_value
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._deploy_binaries_and_conf(
         'localhost', 'username', 'exec', '/path/to/exec',
         '/home/.clusterrunner/clusterrunner_prime.conf')
     self.assertTrue(mock_DeployTarget_instance.deploy_conf.called)
Exemplo n.º 7
0
 def test_deploy_binaries_and_conf_doesnt_deploy_binaries_if_localhost_and_same_executable_path_in_use(
         self):
     self.patch('os.path.expanduser').return_value = '/home'
     mock_DeployTarget = self.patch(
         'app.subcommands.deploy_subcommand.DeployTarget')
     mock_DeployTarget_instance = mock_DeployTarget.return_value
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._deploy_binaries_and_conf(
         'localhost', 'username', '/home/.clusterrunner/dist/clusterrunner',
         '/home/.clusterrunner/clusterrunner.tgz', '/clusterrunner.conf')
     self.assertFalse(mock_DeployTarget_instance.deploy_binary.called)
 def test_deploy_binaries_and_conf_deploys_binaries_if_localhost_and_different_executable_path_in_use(self):
     self.patch('os.path.expanduser').return_value = '/home'
     mock_DeployTarget = self.patch('app.subcommands.deploy_subcommand.DeployTarget')
     mock_DeployTarget_instance = mock_DeployTarget.return_value
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._deploy_binaries_and_conf(
         'localhost',
         'username',
         '/home/.clusterrunner/dist/clusterrunner_rime',
         '/home/.clusterrunner/clusterrunner.tgz',
         '/clusterrunner.conf'
     )
     self.assertTrue(mock_DeployTarget_instance.deploy_binary.called)
Exemplo n.º 9
0
    def test_non_registered_slaves_returns_empty_list_if_all_registered(self):
        registered_hosts = ['host_1', 'host_2']
        slaves_to_validate = ['host_1', 'host_2']

        def get_host_id(*args, **kwargs):
            if args[0] == 'host_1':
                return 'host_id_1'
            elif args[0] == 'host_2':
                return 'host_id_2'
            else:
                return 'blah'

        old_host_id = Network.get_host_id
        Network.get_host_id = get_host_id
        deploy_subcommand = DeploySubcommand()
        non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate)
        Network.get_host_id = old_host_id
        self.assertEquals(0, len(non_registered))
    def test_non_registered_slaves_returns_empty_list_if_all_registered(self):
        registered_hosts = ['host_1', 'host_2']
        slaves_to_validate = ['host_1', 'host_2']

        def rsa_key(*args, **kwargs):
            if args[0] == 'host_1':
                return 'rsa_key_1'
            elif args[0] == 'host_2':
                return 'rsa_key_2'
            else:
                return 'blah'

        old_rsa_key = Network.rsa_key
        Network.rsa_key = rsa_key
        deploy_subcommand = DeploySubcommand()
        non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate)
        Network.rsa_key = old_rsa_key
        self.assertEquals(0, len(non_registered))
Exemplo n.º 11
0
    def test_non_registered_slaves_returns_empty_list_if_all_registered(self):
        registered_hosts = ['host_1', 'host_2']
        slaves_to_validate = ['host_1', 'host_2']

        def get_host_id(*args, **kwargs):
            if args[0] == 'host_1':
                return 'host_id_1'
            elif args[0] == 'host_2':
                return 'host_id_2'
            else:
                return 'blah'

        old_host_id = Network.get_host_id
        Network.get_host_id = get_host_id
        deploy_subcommand = DeploySubcommand()
        non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate)
        Network.get_host_id = old_host_id
        self.assertEquals(0, len(non_registered))
Exemplo n.º 12
0
 def test_deploy_binaries_and_conf_behaves_properly_if_conf_or_binary_is_in_use_on_localhost(
         self,
         current_executable,
         in_use_conf_path,
         expect_deploy_conf,
         expect_deploy_binary,
 ):
     mock_DeployTarget = self.patch('app.subcommands.deploy_subcommand.DeployTarget')
     mock_DeployTarget_instance = mock_DeployTarget.return_value
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._deploy_binaries_and_conf(
         'localhost',
         'username',
         current_executable,
         join(expanduser('~'), '.clusterrunner', 'clusterrunner.tgz'),
         in_use_conf_path
     )
     self.assertEqual(expect_deploy_binary, mock_DeployTarget_instance.deploy_binary.called)
     self.assertEqual(expect_deploy_conf, mock_DeployTarget_instance.deploy_conf.called)
Exemplo n.º 13
0
    def test_non_registered_slaves_returns_empty_list_if_all_registered(self):
        registered_hosts = ['host_1', 'host_2']
        slaves_to_validate = ['host_1', 'host_2']

        def rsa_key(*args, **kwargs):
            if args[0] == 'host_1':
                return 'rsa_key_1'
            elif args[0] == 'host_2':
                return 'rsa_key_2'
            else:
                return 'blah'

        old_rsa_key = Network.rsa_key
        Network.rsa_key = rsa_key
        deploy_subcommand = DeploySubcommand()
        non_registered = deploy_subcommand._non_registered_slaves(
            registered_hosts, slaves_to_validate)
        Network.rsa_key = old_rsa_key
        self.assertEquals(0, len(non_registered))
Exemplo n.º 14
0
 def test_deploy_binaries_and_conf_behaves_properly_if_conf_or_binary_is_in_use_on_localhost(
         self,
         current_executable,
         in_use_conf_path,
         expect_deploy_conf,
         expect_deploy_binary,
 ):
     mock_DeployTarget = self.patch('app.subcommands.deploy_subcommand.DeployTarget')
     mock_DeployTarget_instance = mock_DeployTarget.return_value
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._deploy_binaries_and_conf(
         'localhost',
         'username',
         current_executable,
         join(expanduser('~'), '.clusterrunner', 'clusterrunner.tgz'),
         in_use_conf_path
     )
     self.assertEqual(expect_deploy_binary, mock_DeployTarget_instance.deploy_binary.called)
     self.assertEqual(expect_deploy_conf, mock_DeployTarget_instance.deploy_conf.called)
Exemplo n.º 15
0
    def test_non_registered_slaves_returns_empty_list_with_slaves_with_same_host_ids_but_different_names(self):
        registered_hosts = ['host_1_alias', 'host_2_alias']
        slaves_to_validate = ['host_1', 'host_2']

        def get_host_id(*args, **kwargs):
            if args[0] == 'host_1':
                return 'host_id_1'
            elif args[0] == 'host_2':
                return 'host_id_2'
            elif args[0] == 'host_1_alias':
                return 'host_id_1'
            elif args[0] == 'host_2_alias':
                return 'host_id_2'
            else:
                return 'blah'

        self.patch('app.util.network.Network.get_host_id', new=get_host_id)
        deploy_subcommand = DeploySubcommand()
        non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate)
        self.assertEquals(0, len(non_registered))
Exemplo n.º 16
0
    def test_non_registered_slaves_returns_empty_list_with_slaves_with_same_host_ids_but_different_names(self):
        registered_hosts = ['host_1_alias', 'host_2_alias']
        slaves_to_validate = ['host_1', 'host_2']

        def get_host_id(*args, **kwargs):
            if args[0] == 'host_1':
                return 'host_id_1'
            elif args[0] == 'host_2':
                return 'host_id_2'
            elif args[0] == 'host_1_alias':
                return 'host_id_1'
            elif args[0] == 'host_2_alias':
                return 'host_id_2'
            else:
                return 'blah'

        self.patch('app.util.network.Network.get_host_id', new=get_host_id)
        deploy_subcommand = DeploySubcommand()
        non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate)
        self.assertEquals(0, len(non_registered))
Exemplo n.º 17
0
    def test_non_registered_slaves_returns_non_registered_slaves(self):
        registered_hosts = ['host_1', 'host_3']
        slaves_to_validate = ['host_1', 'host_2', 'host_3', 'host_4']

        def get_host_id(*args, **kwargs):
            if args[0] == 'host_1':
                return 'host_id_1'
            elif args[0] == 'host_2':
                return 'host_id_2'
            elif args[0] == 'host_3':
                return 'host_id_3'
            elif args[0] == 'host_4':
                return 'host_id_4'
            else:
                return 'blah'

        self.patch('app.util.network.Network.get_host_id', new=get_host_id)
        deploy_subcommand = DeploySubcommand()
        non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate)
        self.assertEquals(len(non_registered), 2)
        self.assertTrue('host_2' in non_registered)
        self.assertTrue('host_4' in non_registered)
Exemplo n.º 18
0
    def test_non_registered_slaves_returns_non_registered_slaves(self):
        registered_hosts = ['host_1', 'host_3']
        slaves_to_validate = ['host_1', 'host_2', 'host_3', 'host_4']

        def get_host_id(*args, **kwargs):
            if args[0] == 'host_1':
                return 'host_id_1'
            elif args[0] == 'host_2':
                return 'host_id_2'
            elif args[0] == 'host_3':
                return 'host_id_3'
            elif args[0] == 'host_4':
                return 'host_id_4'
            else:
                return 'blah'

        self.patch('app.util.network.Network.get_host_id', new=get_host_id)
        deploy_subcommand = DeploySubcommand()
        non_registered = deploy_subcommand._non_registered_slaves(registered_hosts, slaves_to_validate)
        self.assertEquals(len(non_registered), 2)
        self.assertTrue('host_2' in non_registered)
        self.assertTrue('host_4' in non_registered)
Exemplo n.º 19
0
 def test_binaries_doesnt_raise_exception_if_running_from_bin(self):
     self.patch('os.path.isfile').return_value = True
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._binaries_tar('clusterrunner', '~/.clusterrunner/dist')
Exemplo n.º 20
0
 def test_binaries_tar_raises_exception_if_running_from_source(self):
     deploy_subcommand = DeploySubcommand()
     with self.assertRaisesRegex(SystemExit, '1'):
         deploy_subcommand._binaries_tar('python main.py deploy', '~/.clusterrunner/dist')
Exemplo n.º 21
0
 def test_binaries_doesnt_raise_exception_if_running_from_bin(self):
     self.patch('os.path.isfile').return_value = True
     deploy_subcommand = DeploySubcommand()
     deploy_subcommand._binaries_tar('clusterrunner', '~/.clusterrunner/dist')
Exemplo n.º 22
0
 def test_binaries_tar_raises_exception_if_running_from_source(self):
     deploy_subcommand = DeploySubcommand()
     with self.assertRaisesRegex(SystemExit, '1'):
         deploy_subcommand._binaries_tar('python -m app deploy', '~/.clusterrunner/dist')