def sync(sync_group, retry_timer, ctx):
    try:
        ip = ctx.node.properties['ip']
        user = ctx.node.properties['user']
        password = ctx.node.properties['password']

        ctx.logger.info("Syncing BIG IP: ip={0}, sync_group={1}".format(
            ip, sync_group))

        bigip.do_sync(ip, sync_group, user, password, retry_timer)
    except Exception:
        _, exc_value, exc_traceback = sys.exc_info()
        raise NonRecoverableError(
            "Failed syncing BIG IP with ip '{0}'".format(ip),
            causes=[exception_to_error_cause(exc_value, exc_traceback)])
예제 #2
0
    def test_sync_no_active_device(self):
        # given
        resp_get_device = device_response(failover_state="standby",
                                          second_failover_state="standby")
        expected_error = 'Cannot find an active device'

        with requests_mock.mock() as m:
            # then
            with self.assertRaisesRegexp(BigipSyncException,
                                         expected_error):
                m.get(url_get_device(base_ip),
                      json=resp_get_device,
                      status_code=200)

                # when
                bigip.do_sync(base_ip, sync_group, user, password, 10)
예제 #3
0
    def test_sync_failure_get_400(self):
        # given
        resp_get_device = device_response()
        error_code = 400
        expected_error = 'Received unsupported status code={}'.format(
            error_code
        )

        with requests_mock.mock() as m:
            # then
            with self.assertRaisesRegexp(BigipSyncException,
                                         expected_error):
                m.get(url_get_device(base_ip),
                      json=resp_get_device,
                      status_code=400)

                # when
                bigip.do_sync(base_ip, sync_group, user, password, 10)
예제 #4
0
    def test_sync_success(self):
        # given
        resp_get_device = device_response()
        resp_get_status = status_response()

        with requests_mock.mock() as m:
            m.get(url_get_device(), json=resp_get_device, status_code=200)
            m.post(url_save_device(), status_code=200)
            m.post(url_sync_device(), status_code=200)
            m.get(url_status(), json=resp_get_status, status_code=200)

            # when
            result = bigip.do_sync(base_ip, sync_group, user, password, 10)

        # then
        self.assertIsNone(result)
예제 #5
0
    def test_sync_success_standby(self):
        # given
        mgmt_ip = '1.2.3.5'
        resp_get_device = device_response(failover_state="standby",
                                          mgmt_ip=mgmt_ip)
        resp_get_status = status_response()

        with requests_mock.mock() as m:
            m.get(url_get_device(base_ip),
                  json=resp_get_device,
                  status_code=200)
            m.get(url_get_device(mgmt_ip),
                  json=resp_get_device,
                  status_code=200)
            m.post(url_save_device(mgmt_ip), status_code=200)
            m.post(url_sync_device(mgmt_ip), status_code=200)
            m.get(url_status(mgmt_ip), json=resp_get_status, status_code=200)

            # when
            result = bigip.do_sync(base_ip, sync_group, user, password, 10)

        self.assertIsNone(result)