def test_prednat_no_types(self):
        """
        Test failed conversion with dry-run and start with preDNAT and default Types.
        """

        # Insert using etcdctl because it is not possible to insert a policy with no
        # types using calicoctl from v2.6.5
        testdata = '{ "order":200,"inbound_rules":[{"action":"allow","src_nets":["10.10.10.2/32","10.10.10.3/32","10.10.10.4/32"]}],"pre_dnat":true}'
        etcdv2_edit(
            "set /calico/v1/policy/tier/default/policy/custom-allow '" +
            testdata + "'")

        logger.debug("INFO: dump of etcdv2:")
        dump_etcdv2()
        calicoctlv2("get policy -o yaml")

        rcu = calicoupgrade("dry-run")
        logger.debug("INFO: calico-upgrade dry-run should return 0.")
        rcu.assert_no_error()

        report1 = "convertednames"
        dr_report1 = _get_readlines(report1)
        logger.debug("INFO: calico-upgrade dry-run %s output:\n%s" %
                     (report1, dr_report1))

        rcu = calicoupgrade("start")
        logger.debug("INFO: calico-upgrade start should return 0.")
        rcu.assert_no_error()

        st_report1 = _get_readlines(report1)
        logger.debug("INFO: calico-upgrade start %s output:\n%s" %
                     (report1, st_report1))

        assert dr_report1 == st_report1, \
            "INFO: calico-upgrade dry-run and start %s files are not equal" % report1
Esempio n. 2
0
def test_empty_datastore(cmd):
    """
    Test dry-run and start when the etcdv2 datastore is empty.
    """
    wipe_etcdv2(get_ip())
    dump_etcdv2()
    rcu = calicoupgrade(cmd)
    logger.debug(
        "INFO: empty etcdv2 datastore: Expecting a non-zero" +
        "return code for calico-upgrade %s.", cmd)
    rcu.assert_error()
Esempio n. 3
0
    def test_start_abort_ignore_v3_data(self, testname, no_prompt):
        """
        Test the abort command re-enables the v1 Ready flag.

        calico-upgrade abort - aborts the upgrade process
        by resuming Calico networking for the v2.x nodes.
        """
        prompt_resp = None if no_prompt else "yes"

        testdata = data[testname]

        calicoctlv2("create", data=testdata)
        logger.debug("INFO: dump of etcdv2:")
        dump_etcdv2()

        rcu = calicoupgrade("start", prompt_resp)
        logger.debug("INFO: calico-upgrade start should return 0.")
        rcu.assert_no_error()

        ready_output = get_value_etcdv2("/calico/v1/Ready")
        assert ready_output == "false"

        datastore_ready_rc = _get_ready_etcdv3()
        assert datastore_ready_rc is False

        rcu = calicoupgrade("abort", prompt_resp)
        logger.debug("INFO: calico-upgrade abort should return 0.")
        rcu.assert_no_error()

        ready_output = get_value_etcdv2("/calico/v1/Ready")
        assert ready_output == "true"

        datastore_ready_rc = _get_ready_etcdv3()
        assert datastore_ready_rc is False

        rcu = calicoupgrade("start --ignore-v3-data", prompt_resp)
        logger.debug("INFO: calico-upgrade start should return 0.")
        rcu.assert_no_error()

        ready_output = get_value_etcdv2("/calico/v1/Ready")
        assert ready_output == "false"

        datastore_ready_rc = _get_ready_etcdv3()
        assert datastore_ready_rc is False

        rcu = calicoupgrade("complete", prompt_resp)
        logger.debug("INFO: calico-upgrade complete should return 0.")
        rcu.assert_no_error()

        ready_output = get_value_etcdv2("/calico/v1/Ready")
        assert ready_output == "false"

        datastore_ready_rc = _get_ready_etcdv3()
        assert datastore_ready_rc is True
Esempio n. 4
0
    def test_conversion_failure(self,
                                testname,
                                error_text,
                                report1,
                                report2=None):
        """
        Test failed conversion with dry-run and start file validation.
        etcdv2 Ready and etcdv3 datastoreReady flag validation.
        """

        testdata = data[testname]

        calicoctlv2("create", data=testdata)
        logger.debug("INFO: dump of etcdv2:")
        dump_etcdv2()

        rcu = calicoupgrade("dry-run")
        logger.debug("INFO: calico-upgrade dry-run should return non-zero.")
        rcu.assert_error(error_text)

        ready_output = get_value_etcdv2("/calico/v1/Ready")
        assert ready_output == "true"

        dr_report1 = _get_readlines(report1)
        logger.debug("INFO: calico-upgrade dry-run %s output:\n%s" %
                     (report1, dr_report1))

        if report2 is not None:
            dr_report2 = _get_readlines(report2)
            logger.debug("INFO: calico-upgrade dry-run %s output:\n%s" %
                         (report2, dr_report2))

        rcu = calicoupgrade("start")
        logger.debug("INFO: calico-upgrade dry-run should return non-zero.")
        rcu.assert_error(error_text)

        ready_output = get_value_etcdv2("/calico/v1/Ready")
        assert ready_output == "true"

        st_report1 = _get_readlines(report1)
        logger.debug("INFO: calico-upgrade start %s output:\n%s" %
                     (report1, st_report1))

        assert dr_report1 == st_report1, \
            "INFO: calico-upgrade dry-run and start %s files are not equal" % report1

        if report2 is not None:
            st_report2 = _get_readlines(report2)
            logger.debug("INFO: calico-upgrade dry-run %s output:\n%s" %
                         (report2, st_report2))
            assert dr_report2 == st_report2, \
                "INFO: calico-upgrade dry-run and start %s files are not equal" % report2
Esempio n. 5
0
    def test_conversion(self, testname, no_prompt):
        """
        Test successful conversion of each resource, dry-run and start file validation.
        etcdv2 Ready and etcdv3 datastoreReady flag validation.

        Correctly converted data validated with calicoctlv3 get compared to
        calicoctl convert manifest output.
        """
        prompt_resp = None if no_prompt else "yes"

        testdata = data[testname]
        report1 = "convertednames"

        calicoctlv2("create", data=testdata)
        logger.debug("INFO: dump of etcdv2:")
        dump_etcdv2()

        rcu = calicoupgrade("dry-run")
        logger.debug("INFO: calico-upgrade dry-run should return 0.")
        rcu.assert_no_error()

        ready_output = get_value_etcdv2("/calico/v1/Ready")
        assert ready_output == "true"

        dr_report1 = _get_readlines(report1)
        logger.debug("INFO: calico-upgrade dry-run %s output:\n%s" %
                     (report1, dr_report1))

        rcu = calicoupgrade("start", prompt_resp)
        logger.debug("INFO: calico-upgrade start should return 0.")
        rcu.assert_no_error()

        ready_output = get_value_etcdv2("/calico/v1/Ready")
        assert ready_output == "false"

        datastore_ready_rc = _get_ready_etcdv3()
        assert datastore_ready_rc is False

        st_report1 = _get_readlines(report1)
        logger.debug("INFO: calico-upgrade start %s output:\n%s" %
                     (report1, st_report1))

        assert dr_report1 == st_report1, \
            "INFO: calico-upgrade dry-run and start %s files are not equal" % report1

        rcc = calicoctl("convert", data=testdata)
        rcc.assert_no_error()

        parsed_output = yaml.safe_load(rcc.output)
        converted_data = clean_calico_data(parsed_output)
        logger.debug("INFO: converted data to v3\n%s" % converted_data)
        original_resource = rcc

        rcc = calicoctl("get %s %s -o yaml" %
                        (converted_data['kind'], name(converted_data)))
        logger.debug(
            "INFO: calicoctl (v3) get - after calico-upgrade start: \n%s" %
            rcc.output)

        # Comparison here needs to be against cleaned versions of data to remove Creation Timestamp
        logger.debug("Comparing 'get'ted output with original converted yaml")
        cleaned_output = yaml.safe_dump(
            clean_calico_data(yaml.safe_load(rcc.output),
                              extra_keys_to_remove=[
                                  'projectcalico.org/orchestrator', 'namespace'
                              ]))
        original_resource.assert_data(cleaned_output)

        rcu = calicoupgrade("complete", prompt_resp)
        logger.debug("INFO: calico-upgrade complete should return 0.")
        rcu.assert_no_error()

        ready_output = get_value_etcdv2("/calico/v1/Ready")
        assert ready_output == "false"

        datastore_ready_rc = _get_ready_etcdv3()
        assert datastore_ready_rc is True