def createService(
     self, cluster_object: V1MongoClusterConfiguration
 ) -> Optional[client.V1Service]:
     """
     Creates the given cluster.
     :param cluster_object: The cluster object from the YAML file.
     :return: The created service.
     """
     namespace = cluster_object.metadata.namespace
     body = KubernetesResources.createService(cluster_object)
     logging.info("Creating service %s @ ns/%s.", body.metadata.name,
                  namespace)
     with IgnoreIfExists():
         return self.core_api.create_namespaced_service(namespace, body)
 def createStatefulSet(
     self, cluster_object: V1MongoClusterConfiguration
 ) -> Optional[client.V1beta1StatefulSet]:
     """
     Creates the stateful set for the given cluster object.
     :param cluster_object: The cluster object from the YAML file.
     :return: The created stateful set.
     """
     namespace = cluster_object.metadata.namespace
     body = KubernetesResources.createStatefulSet(cluster_object)
     with IgnoreIfExists():
         logging.info("Creating stateful set %s @ ns/%s.",
                      body.metadata.name, namespace)
         return self.apps_api.create_namespaced_stateful_set(
             namespace, body)
 def createSecret(
         self,
         secret_name: str,
         namespace: str,
         secret_data: Dict[str, str],
         labels: Optional[Dict[str,
                               str]] = None) -> Optional[client.V1Secret]:
     """
     Creates a new Kubernetes secret.
     :param secret_name: Unique name of the secret.
     :param namespace: Namespace to add secret to.
     :param secret_data: The data to store in the secret as key/value pair dict.
     :param labels: Optional labels for this secret, defaults to the default labels (see `cls.createDefaultLabels`).
     :return: The secret if successful, None otherwise.
     """
     secret_body = KubernetesResources.createSecret(secret_name, namespace,
                                                    secret_data, labels)
     logging.info("Creating secret %s in namespace %s", secret_name,
                  namespace)
     with IgnoreIfExists():
         return self.core_api.create_namespaced_secret(
             namespace, secret_body)
 def test_api_exception_code_409(self):
     with IgnoreIfExists():
         raise ApiException(http_resp=MagicMock(status=409, data="{}"))
 def test_api_exception_code_not_409(self):
     with self.assertRaises(ApiException):
         with IgnoreIfExists():
             raise ApiException(http_resp=MagicMock(status=400, data="{}"))
 def test_no_api_exception(self):
     with self.assertRaises(ValueError):
         with IgnoreIfExists():
             raise ValueError()
 def test_no_error(self):
     with IgnoreIfExists():
         pass