コード例 #1
0
	def upgrade(self):		
		etag = generate_etag()
		Printer.start_test("Update plan")

		# CHECK: Plan upgrade succeeds
		(status, response) = self.client.perform_request(
				"subscriptions/%s/cloudservices/%s/resources/%s/%s" % (
					self.config["subscription_id"],
					self.config["cloud_service_name"],
					self.config["resource_type"],
					self.config["resource_name"]),
				'PUT',
				xmlutil.xml_for_create_resource(
					plan=self.config['upgrade_plan'],
					resource_type=self.config['resource_type'],
					promotion_code=self.config['promo_code'],
					etag=etag
				),
				validate_xml=True
			)

		if status in [200, 201]:
			Printer.success("Upgrade Resource succeeded.")
			Printer.info("Checking XML")
		else:
			Printer.error("Upgrade Resource failed with HTTP status code %s" % status)
			return

		t = xmlutil.get_subtree_from_xml_string(response)
		self._validate_resource_response(etag, t)
		Printer.info("Checking if new plan is %s" % self.config['upgrade_plan'])
		self._check_node_value(t, './{0}Plan', self.config['upgrade_plan'])
コード例 #2
0
    def upgrade(self):
        etag = generate_etag()
        Printer.start_test("Update plan")

        # CHECK: Plan upgrade succeeds
        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s" %
            (self.config["subscription_id"], self.config["cloud_service_name"],
             self.config["resource_type"], self.config["resource_name"]),
            'PUT',
            xmlutil.xml_for_create_resource(
                plan=self.config['upgrade_plan'],
                resource_type=self.config['resource_type'],
                promotion_code=self.config['promo_code'],
                etag=etag),
            validate_xml=True)

        if status in [200, 201]:
            Printer.success("Upgrade Resource succeeded.")
            Printer.info("Checking XML")
        else:
            Printer.error("Upgrade Resource failed with HTTP status code %s" %
                          status)
            return

        t = xmlutil.get_subtree_from_xml_string(response)
        self._validate_resource_response(etag, t)
        Printer.info("Checking if new plan is %s" %
                     self.config['upgrade_plan'])
        self._check_node_value(t, './{0}Plan', self.config['upgrade_plan'])
コード例 #3
0
	def get_cloud_service(self):
		Printer.start_test("Get CloudService")

		(status, response) = self.client.perform_request(
				"subscriptions/%s/cloudservices/%s" % (
					self.config["subscription_id"],
					self.config["cloud_service_name"]
					),
				"GET",
				None,
				validate_xml=True
			)
		
		if status in [200, 201]:
			Printer.success("Get CloudService succeeded.")
			Printer.info("Checking XML")
		else:
			Printer.error("Get CloudService failed with HTTP status code %s" % status)
			return

		t = xmlutil.get_subtree_from_xml_string(response)
		root_node_expected_tag = '{0}CloudService'.format(xmlutil.get_namespace(t))
		root_node_actual_tag = xmlutil.get_root_tag(t)
		if (root_node_expected_tag != root_node_actual_tag):
			Printer.error("Root node does not have expected tag %s" % root_node_expected_tag)
			return

		resource_names = map(lambda t: t.text, xmlutil.get_nodes(t, ".//{0}Resource/{0}Name"))
		
		if self.config['resource_name'] not in resource_names:
			Printer.error("Resource named '%s' not returned by endpoint" % self.config['resource_name'])
コード例 #4
0
    def get_resource(self):
        Printer.start_test("Get Resource")

        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s"
            % (
                self.config["subscription_id"],
                self.config["cloud_service_name"],
                self.config["resource_type"],
                self.config["resource_name"],
            ),
            "GET",
            None,
            validate_xml=True,
        )

        if status in [200, 201]:
            Printer.success("Get resource succeeded.")
            Printer.info("Checking XML")
        else:
            Printer.error("Get resource failed with HTTP status code %s" % status)
            return

        t = xmlutil.get_subtree_from_xml_string(response)
        self._validate_resource_response(None, t)
コード例 #5
0
    def get_cloud_service(self):
        Printer.start_test("Get CloudService")

        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s" %
            (self.config["subscription_id"],
             self.config["cloud_service_name"]),
            "GET",
            None,
            validate_xml=True)

        if status in [200, 201]:
            Printer.success("Get CloudService succeeded.")
            Printer.info("Checking XML")
        else:
            Printer.error("Get CloudService failed with HTTP status code %s" %
                          status)
            return

        t = xmlutil.get_subtree_from_xml_string(response)
        root_node_expected_tag = '{0}CloudService'.format(
            xmlutil.get_namespace(t))
        root_node_actual_tag = xmlutil.get_root_tag(t)
        if (root_node_expected_tag != root_node_actual_tag):
            Printer.error("Root node does not have expected tag %s" %
                          root_node_expected_tag)
            return

        resource_names = map(lambda t: t.text,
                             xmlutil.get_nodes(t, ".//{0}Resource/{0}Name"))

        if self.config['resource_name'] not in resource_names:
            Printer.error("Resource named '%s' not returned by endpoint" %
                          self.config['resource_name'])
コード例 #6
0
    def delete(self):
        etag = generate_etag()
        Printer.start_test("Delete Resource")

        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s" %
            (self.config["subscription_id"], self.config["cloud_service_name"],
             self.config["resource_type"], self.config["resource_name"]),
            'DELETE', None)

        if status in [200, 201]:
            Printer.success("Delete Resource succeeded.")
        else:
            Printer.error("Delete Resource failed with HTTP status code %s" %
                          status)
            return
コード例 #7
0
    def create(self):
        etag = generate_etag()
        Printer.start_test("Create resource")
        (status, response) = self.client.perform_request(
            "subscriptions/%s/Events" % self.config["subscription_id"],
            "POST",
            xmlutil.xml_for_subscription_event(
                self.config["subscription_id"],
                self.config["resource_provider_namespace"],
                self.config["resource_type"],
                "Registered",
            ),
        )

        # CHECK: Subscription Register event succeeds
        if status in [200, 201]:
            Printer.success("Subscription register event succeeded")
        else:
            Printer.error("Subscription register event failed with HTTP status code %s" % status)
            return

            # CHECK: Resource creation succeeds
        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s"
            % (
                self.config["subscription_id"],
                self.config["cloud_service_name"],
                self.config["resource_type"],
                self.config["resource_name"],
            ),
            "PUT",
            xmlutil.xml_for_create_resource(
                plan=self.config["purchase_plan"],
                resource_type=self.config["resource_type"],
                promotion_code=self.config["promo_code"],
                etag=etag,
            ),
        )

        if status in [200, 201]:
            Printer.success("Resource creation succeeded")
            Printer.info("Checking XML")
        else:
            Printer.error("Resource creation event failed with HTTP status code %s" % status)

        t = xmlutil.get_subtree_from_xml_string(response)
        self._validate_resource_response(etag, t)
コード例 #8
0
	def delete(self):
		etag = generate_etag()
		Printer.start_test("Delete Resource")

		(status, response) = self.client.perform_request(
				"subscriptions/%s/cloudservices/%s/resources/%s/%s" % (
					self.config["subscription_id"],
					self.config["cloud_service_name"],
					self.config["resource_type"],
					self.config["resource_name"]),
				'DELETE',
				None
			)

		if status in [200, 201]:
			Printer.success("Delete Resource succeeded.")
		else:
			Printer.error("Delete Resource failed with HTTP status code %s" % status)
			return
コード例 #9
0
    def create(self):
        etag = generate_etag()
        Printer.start_test("Create resource")
        (status, response) = self.client.perform_request(
            "subscriptions/%s/Events" % self.config['subscription_id'], 'POST',
            xmlutil.xml_for_subscription_event(
                self.config["subscription_id"],
                self.config["resource_provider_namespace"],
                self.config["resource_type"], "Registered"))

        # CHECK: Subscription Register event succeeds
        if status in [200, 201]:
            Printer.success("Subscription register event succeeded")
        else:
            Printer.error(
                "Subscription register event failed with HTTP status code %s" %
                status)
            return

        # CHECK: Resource creation succeeds
        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s" %
            (self.config["subscription_id"], self.config["cloud_service_name"],
             self.config["resource_type"], self.config["resource_name"]),
            'PUT',
            xmlutil.xml_for_create_resource(
                plan=self.config['purchase_plan'],
                resource_type=self.config['resource_type'],
                promotion_code=self.config['promo_code'],
                etag=etag))

        if status in [200, 201]:
            Printer.success("Resource creation succeeded")
            Printer.info("Checking XML")
        else:
            Printer.error(
                "Resource creation event failed with HTTP status code %s" %
                status)

        t = xmlutil.get_subtree_from_xml_string(response)
        self._validate_resource_response(etag, t)
コード例 #10
0
    def get_resource(self):
        Printer.start_test("Get Resource")

        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s" %
            (self.config["subscription_id"], self.config["cloud_service_name"],
             self.config["resource_type"], self.config["resource_name"]),
            "GET",
            None,
            validate_xml=True)

        if status in [200, 201]:
            Printer.success("Get resource succeeded.")
            Printer.info("Checking XML")
        else:
            Printer.error("Get resource failed with HTTP status code %s" %
                          status)
            return

        t = xmlutil.get_subtree_from_xml_string(response)
        self._validate_resource_response(None, t)
コード例 #11
0
	def sso(self):
		Printer.start_test("SSO with valid timestamp and token")
		(status, response) = self.client.perform_request(
				"subscriptions/%s/cloudservices/%s/resources/%s/%s/SsoToken" % (
						self.config["subscription_id"],
						self.config["cloud_service_name"],
						self.config["resource_type"],
						self.config["resource_name"]
					),
				"POST",
				None,
				validate_xml=True
			)

		if status in [200, 201]:
			Printer.success("SSO token request succeeded.")
			Printer.info("Checking XML")
		else:
			Printer.error("SSO token request failed with HTTP status code %s" % status)
			return

		t = xmlutil.get_subtree_from_xml_string(response)
		self._check_node_exists(t, "./{0}SsoToken/TimeStamp")
		self._check_node_exists(t, "./{0}SsoToken/Token")

		fragment = urllib.urlencode(
				{
					"token": xmlutil.get_node_value(t, "./{0}Token"),
					"timestamp": xmlutil.get_node_value(t, "./{0}TimeStamp")
				}
			)

		(status, response) = self.client.perform_request(
				"?subid=%s&cloudservicename=%s&resourcetype=%s&resourcename=%s&%s" % (
			 		self.config["subscription_id"], 
			 		self.config["cloud_service_name"],
			  		self.config["resource_type"],
			 		self.config["resource_name"],
			 		fragment
					),
				"GET",
				None,
				uri_type="sso",
				validate_xml=False
			)

		if status in [200, 201]:
			Printer.success("SSO login succeeded.")
		else:
			Printer.error("SSO login request failed with HTTP status code %s" % status)
			return


		Printer.start_test("SSO with expired timestamp")
		given_timestamp = iso8601.parse_date(xmlutil.get_node_value(t, "./{0}TimeStamp"))
		expired_timestamp = given_timestamp + timedelta(seconds=60*10)
		
		fragment = urllib.urlencode(
				{
					"token": xmlutil.get_node_value(t, "./{0}Token"),
					"timestamp": str(expired_timestamp)
				}
			)

		(status, response) = self.client.perform_request(
				"sso?subid=%s&cloudservicename=%s&resourcetype=%s&resourcename=%s&%s" % (
			 		self.config["subscription_id"], 
			 		self.config["cloud_service_name"],
			  		self.config["resource_type"],
			 		self.config["resource_name"],
			 		fragment
					),
				"GET",
				None,
				uri_type="sso",
				validate_xml=False
			)

		if status in [200, 201]:
			Printer.error("SSO login with expired timestamp succeeded.")
		else:
			Printer.success("SSO login with expired timestamp failed with error code %s" % status)
			return
コード例 #12
0
    def sso(self):
        Printer.start_test("SSO with valid timestamp and token")
        (status, response) = self.client.perform_request(
            "subscriptions/%s/cloudservices/%s/resources/%s/%s/SsoToken" %
            (self.config["subscription_id"], self.config["cloud_service_name"],
             self.config["resource_type"], self.config["resource_name"]),
            "POST",
            None,
            validate_xml=True)

        if status in [200, 201]:
            Printer.success("SSO token request succeeded.")
            Printer.info("Checking XML")
        else:
            Printer.error("SSO token request failed with HTTP status code %s" %
                          status)
            return

        t = xmlutil.get_subtree_from_xml_string(response)
        self._check_node_exists(t, "./{0}SsoToken/TimeStamp")
        self._check_node_exists(t, "./{0}SsoToken/Token")

        fragment = urllib.urlencode({
            "token":
            xmlutil.get_node_value(t, "./{0}Token"),
            "timestamp":
            xmlutil.get_node_value(t, "./{0}TimeStamp")
        })

        (status, response) = self.client.perform_request(
            "?subid=%s&cloudservicename=%s&resourcetype=%s&resourcename=%s&%s"
            % (self.config["subscription_id"],
               self.config["cloud_service_name"], self.config["resource_type"],
               self.config["resource_name"], fragment),
            "GET",
            None,
            uri_type="sso",
            validate_xml=False)

        if status in [200, 201]:
            Printer.success("SSO login succeeded.")
        else:
            Printer.error("SSO login request failed with HTTP status code %s" %
                          status)
            return

        Printer.start_test("SSO with expired timestamp")
        given_timestamp = iso8601.parse_date(
            xmlutil.get_node_value(t, "./{0}TimeStamp"))
        expired_timestamp = given_timestamp + timedelta(seconds=60 * 10)

        fragment = urllib.urlencode({
            "token":
            xmlutil.get_node_value(t, "./{0}Token"),
            "timestamp":
            str(expired_timestamp)
        })

        (status, response) = self.client.perform_request(
            "sso?subid=%s&cloudservicename=%s&resourcetype=%s&resourcename=%s&%s"
            % (self.config["subscription_id"],
               self.config["cloud_service_name"], self.config["resource_type"],
               self.config["resource_name"], fragment),
            "GET",
            None,
            uri_type="sso",
            validate_xml=False)

        if status in [200, 201]:
            Printer.error("SSO login with expired timestamp succeeded.")
        else:
            Printer.success(
                "SSO login with expired timestamp failed with error code %s" %
                status)
            return