Example #1
0
 def setup_mock_options(cls):
     """set up to get a mock options object."""
     mock_options = Mock(
         spec=[
             "json",
             "bindings",
             "open_browser",
             "shards",
             "cluster",
             "health_check_interval_seconds",
             "batch_size",
             "max_per_shard_failures",
             "max_total_failures",
             "restart_threshold",
             "watch_secs",
         ]
     )
     mock_options.json = False
     mock_options.bindings = {}
     mock_options.open_browser = False
     mock_options.shards = None
     mock_options.cluster = None
     mock_options.health_check_interval_seconds = 3
     mock_options.batch_size = 5
     mock_options.max_per_shard_failures = 0
     mock_options.max_total_failures = 0
     mock_options.restart_threshold = 30
     mock_options.watch_secs = 30
     mock_options.disable_all_hooks_reason = None
     return mock_options
    def test_deploy_image_error(self):

        PROCESS.communicate = Mock(return_value=["error"])
        ovf = OvfImageDeployerService("dummypath/ovftool.exe")
        image_params = Mock()
        image_params.connectivity = VCenterConnectionDetails("venter.host.com", "vcenter user", "password to vcenter")
        image_params.datacenter = "QualiSB"
        image_params.cluster = "QualiSB Cluster"
        image_params.resource_pool = "LiverPool"
        image_params.vm_name = "raz_deploy_image_integration_test"
        image_params.datastore = "aa"
        # image_params.image_url = "C:\\images\\test\\OVAfile121_QS\\OVAfile121_QS.ovf"
        image_params.image_url = "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf"

        image_params.user_arguments = '--vlan="anetwork"'

        ovf._validate_url_exists = Mock(return_value=True)

        vcenter_data_model = Mock()
        vcenter_data_model.ovf_tool_path = "dummypath/ovftool.exe"

        try:
            ovf.deploy_image(vcenter_data_model, image_params, logger=Mock())
            # should not reach here
            self.assertTrue(False)
        except Exception as inst:
            self.assertTrue(inst.message.find("password to vcenter") == -1)
            self.assertTrue(inst.message.find(urllib.quote_plus("******")) > -1)
            self.assertTrue(PROCESS.stdin.close.called)
 def make_mock_options(self):
     mock_options = Mock()
     mock_options.filename = None
     mock_options.hosts = ",".join(self.HOSTNAMES)
     mock_options.cluster = self.TEST_CLUSTER
     mock_options.verbosity = False
     return mock_options
 def setup_mock_options(cls):
     """set up to get a mock options object."""
     mock_options = Mock()
     mock_options.open_browser = False
     mock_options.shards = None
     mock_options.cluster = None
     mock_options.json = False
     return mock_options
def test_lookup_configs():
    expected_system_type = "deb"

    def make_remote():
        remote = Mock()
        remote.arch = "x86_64"
        remote.os = Mock()
        remote.os.name = "ubuntu"
        remote.os.version = "14.04"
        remote.os.codename = "trusty"
        remote.system_type = expected_system_type
        return remote

    ctx = Mock()

    class cluster:
        remote1 = make_remote()
        remote2 = make_remote()
        remotes = {remote1: ["client.0"], remote2: ["mon.a", "osd.0"]}

        def only(self, role):
            result = Mock()
            if role in ("client.0",):
                result.remotes = {cluster.remote1: None}
            elif role in ("osd.0", "mon.a"):
                result.remotes = {cluster.remote2: None}
            else:
                result.remotes = None
            return result

    ctx.cluster = cluster()
    ctx.config = {"roles": [["client.0"], ["mon.a", "osd.0"]]}

    # nothing -> nothing
    assert buildpackages.lookup_configs(ctx, {}) == []
    assert buildpackages.lookup_configs(ctx, {1: [1, 2, 3]}) == []
    assert buildpackages.lookup_configs(ctx, [[1, 2, 3]]) == []
    assert buildpackages.lookup_configs(ctx, None) == []

    #
    # the overrides applies to install and to install.upgrade
    # that have no tag, branch or sha1
    #
    config = {
        "overrides": {"install": {"ceph": {"sha1": "overridesha1", "tag": "overridetag", "branch": "overridebranch"}}},
        "tasks": [
            {"install": {"sha1": "installsha1"}},
            {"install.upgrade": {"osd.0": {}, "client.0": {"sha1": "client0sha1"}}},
        ],
    }
    ctx.config = config
    expected_configs = [
        {"branch": "overridebranch", "sha1": "overridesha1", "tag": "overridetag"},
        {"project": "ceph", "branch": "overridebranch", "sha1": "overridesha1", "tag": "overridetag"},
        {"project": "ceph", "sha1": "client0sha1"},
    ]

    assert buildpackages.lookup_configs(ctx, config) == expected_configs
Example #6
0
 def setup_mock_options(cls):
     """set up to get a mock options object."""
     mock_options = Mock()
     mock_options.json = False
     mock_options.bindings = {}
     mock_options.open_browser = False
     mock_options.cluster = None
     mock_options.wait_until = "RUNNING"  # or 'FINISHED' for other tests
     return mock_options
Example #7
0
    def test_create_mon_path_if_nonexistent(self):
        self.distro.sudo_conn.modules.os.path.exists = Mock(side_effect=path_exists(["/"]))
        args = Mock(return_value=["cluster", "1234", "initd"])
        args.cluster = "cluster"
        with patch("ceph_deploy.hosts.common.conf.load"):
            mon_create(self.distro, self.logger, args, Mock(), "hostname")

        result = self.distro.sudo_conn.modules.os.makedirs.call_args_list[0]
        assert result == call("/var/lib/ceph/mon/cluster-hostname")
def test_emergency_start(mock_service_name, mock_execute, mock_load_config):
    args = Mock()
    args.service = "fake_service"
    args.soa_dir = "fakesoadir/"
    args.cluster = "fakecluster"
    args.instance = "fakeinstance"
    emergency_start.paasta_emergency_start(args)
    mock_execute.assert_called_with(
        subcommand="start", cluster=args.cluster, service=args.service, instances=args.instance, system_paasta_config={}
    )
Example #9
0
 def setup_mock_options(cls):
     """set up to get a mock options object."""
     mock_options = Mock()
     mock_options.env = None
     mock_options.json = False
     mock_options.bindings = {}
     mock_options.open_browser = False
     mock_options.rename_from = None
     mock_options.cluster = None
     return mock_options
Example #10
0
    def test_create_mon_tmp_path_if_nonexistent(self):
        self.distro.sudo_conn.modules.os.path.exists = Mock(side_effect=path_exists(["/cluster-hostname"]))
        self.paths.mon.constants.tmp_path = "/var/lib/ceph/tmp"
        args = Mock(return_value=["cluster", "1234", "initd"])
        args.cluster = "cluster"
        with patch("ceph_deploy.hosts.common.conf.load"):
            mon_create(self.distro, args, Mock(), "hostname")

        result = self.distro.conn.remote_module.create_mon_path.call_args_list[-1]
        assert result == mock.call("/var/lib/ceph/mon/cluster-hostname")
Example #11
0
    def test_write_keyring(self):
        self.distro.sudo_conn.modules.os.path.exists = Mock(side_effect=path_exists(["/"]))
        args = Mock(return_value=["cluster", "1234", "initd"])
        args.cluster = "cluster"
        with patch("ceph_deploy.hosts.common.conf.load"):
            with patch("ceph_deploy.hosts.common.remote") as fake_remote:
                mon_create(self.distro, self.logger, args, Mock(), "hostname")

        # the second argument to `remote()` should be the write func
        result = fake_remote.call_args_list[1][0][-1].__name__
        assert result == "write_monitor_keyring"
Example #12
0
    def test_write_init_path(self):
        self.distro.sudo_conn.modules.os.path.exists = Mock(side_effect=path_exists(["/"]))
        args = Mock(return_value=["cluster", "1234", "initd"])
        args.cluster = "cluster"

        with patch("ceph_deploy.hosts.common.conf.load"):
            with patch("ceph_deploy.hosts.common.remote") as fake_remote:
                mon_create(self.distro, self.logger, args, Mock(), "hostname")

        result = fake_remote.call_args_list[-1][0][-1].__name__
        assert result == "create_init_path"
Example #13
0
 def setup_mock_options(cls):
     """set up to get a mock options object."""
     mock_options = Mock()
     mock_options.open_browser = False
     mock_options.shards = None
     mock_options.cluster = None
     mock_options.json = False
     mock_options.batch_size = None
     mock_options.max_total_failures = 1
     mock_options.disable_all_hooks = False
     return mock_options
 def make_mock_options(self):
     mock_options = Mock()
     mock_options.filename = None
     mock_options.hosts = ",".join(self.HOSTNAMES)
     mock_options.cluster = self.TEST_CLUSTER
     mock_options.verbosity = False
     mock_options.disable_all_hooks = False
     mock_options.percentage = None
     mock_options.duration = None
     mock_options.reason = None
     return mock_options
 def setup_mock_options(cls):
     """set up to get a mock options object."""
     mock_options = Mock()
     mock_options.json = False
     mock_options.bindings = {}
     mock_options.open_browser = False
     mock_options.cluster = None
     mock_options.force = True
     mock_options.env = None
     mock_options.shards = None
     mock_options.health_check_interval_seconds = 3
     return mock_options
Example #16
0
 def setup_mock_options(cls):
     """set up to get a mock options object."""
     mock_options = Mock()
     mock_options.json = False
     mock_options.bindings = {}
     mock_options.open_browser = False
     mock_options.shards = None
     mock_options.cluster = None
     mock_options.health_check_interval_secs = 3
     mock_options.batch_size = 5
     mock_options.max_per_shard_failures = 0
     mock_options.max_total_failures = 0
     mock_options.restart_threshold = 30
     mock_options.watch_secs = 30
     return mock_options
    def test_deploy_image_no_communication(self):

        PROCESS.communicate = Mock(return_value=None)
        ovf = OvfImageDeployerService("dummypath/ovftool.exe")
        image_params = Mock()
        image_params.connectivity = VCenterConnectionDetails("venter.host.com", "vcenter user", "password to vcenter")

        image_params.datacenter = "QualiSB"
        image_params.cluster = "QualiSB Cluster"
        image_params.vm_name = "raz_deploy_image_integration_test"
        image_params.resource_pool = "LiverPool"
        image_params.datastore = "aa"
        # image_params.image_url = "C:\\images\\test\\OVAfile121_QS\\OVAfile121_QS.ovf"
        image_params.image_url = "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf"
        image_params.user_arguments = '--vlan="anetwork"'

        vcenter_data_model = Mock()
        vcenter_data_model.ovf_tool_path = "dummypath/ovftool.exe"
        ovf._validate_url_exists = Mock(return_value=True)

        self.assertRaises(Exception, ovf.deploy_image, vcenter_data_model, image_params)
        self.assertTrue(PROCESS.stdin.close.called)
    def test_deploy_image_success(self):
        PROCESS.communicate = Mock(return_value=["Completed successfully"])
        expected_args = [
            "dummypath/ovftool.exe",
            "--noSSLVerify",
            "--acceptAllEulas",
            "--powerOffTarget",
            "--name=raz_deploy_image_integration_test",
            "--datastore=aa",
            "--vmFolder=Raz",
            '--vlan="anetwork"',
            "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf",
            "vi://vcenter%20user:password%20to%20vcenter@venter.host.com/QualiSB/host/QualiSB%20Cluster/Resources/LiverPool",
        ]
        ovf = OvfImageDeployerService("dummypath/ovftool.exe")
        image_params = Mock()
        image_params.connectivity = VCenterConnectionDetails("venter.host.com", "vcenter user", "password to vcenter")

        image_params.datacenter = "QualiSB"
        image_params.cluster = "QualiSB Cluster"
        image_params.resource_pool = "LiverPool"
        image_params.vm_name = "raz_deploy_image_integration_test"
        image_params.datastore = "aa"
        image_params.power_on = "false"
        image_params.vm_folder = "Raz"
        # image_params.image_url = "C:\\images\\test\\OVAfile121_QS\\OVAfile121_QS.ovf"
        image_params.image_url = "http://192.168.65.88/ovf/Debian 64 - Yoav.ovf"
        image_params.user_arguments = '--vlan="anetwork"'

        vcenter_data_model = Mock()
        vcenter_data_model.ovf_tool_path = "dummypath/ovftool.exe"

        ovf._validate_url_exists = Mock(return_value=True)

        res = ovf.deploy_image(vcenter_data_model, image_params, logger=Mock())

        self.assertTrue(res)
        self.assertEqual(PROCESS.args, expected_args)
        self.assertTrue(PROCESS.stdin.close.called)
Example #19
0
    def test_upgrade_common(self, m_verify_package_version, m_get_system_type):
        expected_system_type = "deb"

        def make_remote():
            remote = Mock()
            remote.arch = "x86_64"
            remote.os = Mock()
            remote.os.name = "ubuntu"
            remote.os.version = "14.04"
            remote.os.codename = "trusty"
            remote.system_type = expected_system_type
            return remote

        ctx = Mock()

        class cluster:
            remote1 = make_remote()
            remote2 = make_remote()
            remotes = {remote1: ["client.0"], remote2: ["mon.a", "osd.0"]}

            def only(self, role):
                result = Mock()
                if role in ("client.0",):
                    result.remotes = {cluster.remote1: None}
                if role in ("osd.0", "mon.a"):
                    result.remotes = {cluster.remote2: None}
                return result

        ctx.cluster = cluster()
        config = {"client.0": {"sha1": "expectedsha1"}}
        ctx.config = {"roles": [["client.0"], ["mon.a", "osd.0"]], "tasks": [{"install.upgrade": config}]}
        m_get_system_type.return_value = "deb"

        def upgrade(ctx, node, remote, pkgs, system_type):
            assert system_type == expected_system_type

        assert install.upgrade_common(ctx, config, upgrade) == 1
        expected_config = {"project": "ceph", "sha1": "expectedsha1"}
        m_verify_package_version.assert_called_with(ctx, expected_config, cluster.remote1)
Example #20
0
    def test_upgrade_remote_to_config(self):
        expected_system_type = "deb"

        def make_remote():
            remote = Mock()
            remote.arch = "x86_64"
            remote.os = Mock()
            remote.os.name = "ubuntu"
            remote.os.version = "14.04"
            remote.os.codename = "trusty"
            remote.system_type = expected_system_type
            return remote

        ctx = Mock()

        class cluster:
            remote1 = make_remote()
            remote2 = make_remote()
            remotes = {remote1: ["client.0"], remote2: ["mon.a", "osd.0"]}

            def only(self, role):
                result = Mock()
                if role in ("client.0",):
                    result.remotes = {cluster.remote1: None}
                elif role in ("osd.0", "mon.a"):
                    result.remotes = {cluster.remote2: None}
                else:
                    result.remotes = None
                return result

        ctx.cluster = cluster()
        ctx.config = {"roles": [["client.0"], ["mon.a", "osd.0"]]}

        # nothing -> nothing
        assert install.upgrade_remote_to_config(ctx, {}) == {}

        # select the remote for the osd.0 role
        # the 'ignored' role does not exist and is ignored
        # the remote for mon.a is the same as for osd.0 and
        # is silently ignored (actually it could be the other
        # way around, depending on how the keys are hashed)
        config = {"osd.0": {"sha1": "expectedsha1"}, "ignored": None, "mon.a": {"sha1": "expectedsha1"}}
        expected_config = {cluster.remote2: {"project": "ceph", "sha1": "expectedsha1"}}
        assert install.upgrade_remote_to_config(ctx, config) == expected_config

        # select all nodes, regardless
        config = {"all": {"sha1": "expectedsha1"}}
        expected_config = {
            cluster.remote1: {"project": "ceph", "sha1": "expectedsha1"},
            cluster.remote2: {"project": "ceph", "sha1": "expectedsha1"},
        }
        assert install.upgrade_remote_to_config(ctx, config) == expected_config

        # verify that install overrides are used as default
        # values for the upgrade task, not as override
        ctx.config["overrides"] = {
            "install": {"ceph": {"sha1": "overridesha1", "tag": "overridetag", "branch": "overridebranch"}}
        }
        config = {"client.0": {"sha1": "expectedsha1"}, "osd.0": {}}
        expected_config = {
            cluster.remote1: {"project": "ceph", "sha1": "expectedsha1"},
            cluster.remote2: {
                "project": "ceph",
                "sha1": "overridesha1",
                "tag": "overridetag",
                "branch": "overridebranch",
            },
        }
        assert install.upgrade_remote_to_config(ctx, config) == expected_config