<commit_before>(ns celestial.integration.workflows.ec2
  "ec2 workflows"
  (:require 
    [aws.common :refer (with-ctx instance-desc)]
    [celestial.fixtures.core :refer (with-defaults is-type? with-admin with-conf)]  
    [celestial.persistency.systems :as s]
    [celestial.fixtures.data :refer 
     (redis-type redis-ec2-spec local-conf redis-ec2-centos)]  
    [celestial.fixtures.populate :refer (populate-system)]  
    [celestial.integration.workflows.common :refer (spec get-spec)]
    [celestial.workflows :as wf])
  (:import clojure.lang.ExceptionInfo)
  (:use midje.sweet))

(with-admin
  (with-conf local-conf
    (with-state-changes [(before :facts (populate-system redis-type redis-ec2-spec))]
      (fact "aws creation workflows" :integration :ec2 :workflow
          (wf/create (spec)) => nil 
          (wf/create (spec)) => (throws ExceptionInfo  (is-type? :celestial.workflows/machine-exists)) 
          (wf/stop (spec)) => nil 
          (wf/create (spec)) => (throws ExceptionInfo  (is-type? :celestial.workflows/machine-exists)) 
          (wf/destroy (spec)) => nil)

      (fact "aws provisioning workflows" :integration :ec2 :workflow
          (wf/create (spec)) => nil
          (wf/reload (spec)) => nil 
          (wf/destroy (spec)) => nil)

      (fact "vpc" :integration :ec2 :vpc
        ; will be run only if VPC_SUB env var is defined
        (when-let [eip (System/getenv "EIP")]
          (when-let [subnet (System/getenv "VPC_SUB")]
           (wf/create (spec {:machine {:ip eip :os :ubuntu-14.04} :aws {:subnet-id subnet}})) => nil
           #_(wf/stop (spec)) => nil 
           #_(wf/reload (spec {:machine {:ip eip} :aws {:subnet-id subnet}})) => nil 
           ; (instance-desc (get-spec :aws :endpoint) (get-spec :aws :instance-id))
             ;; => (contains {:public-ip-address eip}) 
           ;; (:machine (spec)) => (contains {:ip eip})
           (wf/destroy (spec)) => nil
          )))
      
      (fact "aws eip workflows" :integration :ec2 :workflow
        ; will be run only if EIP env var is defined
        (when-let [eip (System/getenv "EIP")]
           (wf/create (spec {:machine {:ip eip}})) => nil
           (:machine (spec)) => (contains {:ip eip})
           (wf/stop (spec)) => nil 
           (wf/reload (spec)) => nil 
           (instance-desc (get-spec :aws :endpoint) (get-spec :aws :instance-id))
             => (contains {:public-ip-address eip}) 
           (:machine (spec)) => (contains {:ip eip})
           (wf/destroy (spec)) => nil
          ))

      (fact "aws with ebs volumes" :integration :ec2 :workflow
        (let [with-vol {:aws {:volumes [{:device "/dev/sdn" :size 10 :clear true :volume-type "standard" }]}}]
          (wf/create (spec with-vol)) => nil
          (wf/reload (spec with-vol)) => nil 
          (wf/destroy (spec with-vol)) => nil))

      (fact "aws with ephemeral volumes" :integration :ec2 :workflow
        (let [with-vol {:aws {:instance-type "m1.small" :block-devices [{:device-name "/dev/sdb" :virtual-name "ephemeral0" }]}}]
          (wf/create (spec with-vol)) => nil
          (wf/reload (spec with-vol)) => nil 
          (wf/destroy (spec with-vol)) => nil))

      (fact "aws with zone and groups" :integration :ec2 :workflow
        (let [with-zone {:aws {:availability-zone "eu-west-1a" :security-groups ["test"]}} ]
          (wf/create (spec with-zone)) => nil
          (let [{:keys [placement security-groups]} 
                (instance-desc (get-spec :aws :endpoint) 
                               (get-spec :aws :instance-id))]
            placement  => (contains {:availability-zone "eu-west-1a"})
            (first security-groups) => (contains {:group-name "Test"}))
          (wf/reload (spec with-zone)) => nil 
          (wf/destroy (spec with-zone)) => nil))

      (fact "aws puppetization" :integration :ec2 :workflow
          (wf/create (spec)) => nil
          (wf/provision redis-type (spec)) => nil 
          (wf/destroy (spec)) => nil)
<commit_msg>adding vpc with public ip case and enabling all facts on vpc<commit_after>(ns celestial.integration.workflows.ec2
  "ec2 workflows"
  (:require 
    [aws.common :refer (with-ctx instance-desc)]
    [celestial.fixtures.core :refer (with-defaults is-type? with-admin with-conf)]  
    [celestial.persistency.systems :as s]
    [celestial.fixtures.data :refer 
     (redis-type redis-ec2-spec local-conf redis-ec2-centos)]  
    [celestial.fixtures.populate :refer (populate-system)]  
    [celestial.integration.workflows.common :refer (spec get-spec)]
    [celestial.workflows :as wf])
  (:import clojure.lang.ExceptionInfo)
  (:use midje.sweet))

(with-admin
  (with-conf local-conf
    (with-state-changes [(before :facts (populate-system redis-type redis-ec2-spec))]
      (fact "aws creation workflows" :integration :ec2 :workflow
          (wf/create (spec)) => nil 
          (wf/create (spec)) => (throws ExceptionInfo  (is-type? :celestial.workflows/machine-exists)) 
          (wf/stop (spec)) => nil 
          (wf/create (spec)) => (throws ExceptionInfo  (is-type? :celestial.workflows/machine-exists)) 
          (wf/destroy (spec)) => nil)

      (fact "aws provisioning workflows" :integration :ec2 :workflow
          (wf/create (spec)) => nil
          (wf/reload (spec)) => nil 
          (wf/destroy (spec)) => nil)

      (fact "vpc public ip" :integration :ec2 :vpc
        (when-let [subnet (System/getenv "VPC_SUB")]
          (s/update-system 1 
           (spec {
             :machine {:os :ubuntu-14.04} 
             :aws {
               :network-interfaces [
                  {:device-index 0 :associate-public-ip-address true :subnet-id subnet}
               ]
             }}))
          (wf/create (spec)) => nil
          (wf/stop (spec)) => nil 
          (wf/reload (spec)) => nil 
          (wf/destroy (spec)) => nil))

      (fact "vpc eip" :integration :ec2 :vpc
        ; will be run only if VPC_SUB env var is defined
        (when-let [eip (System/getenv "EIP")]
          (when-let [subnet (System/getenv "VPC_SUB")]
           (s/update-system 1 (spec {:machine {:ip eip :os :ubuntu-14.04} :aws {:subnet-id subnet}}))
           (wf/create (spec)) => nil
           (:machine (spec)) => (contains {:ip eip})
           (wf/stop (spec)) => nil 
           (wf/reload (spec)) => nil 
           (instance-desc (get-spec :aws :endpoint) (get-spec :aws :instance-id))
              => (contains {:public-ip-address eip}) 
           (wf/destroy (spec)) => nil)))

      (fact "aws eip workflows" :integration :ec2 :workflow
        ; will be run only if EIP env var is defined
        (when-let [eip (System/getenv "EIP")]
           (wf/create (spec {:machine {:ip eip}})) => nil
           (:machine (spec)) => (contains {:ip eip})
           (wf/stop (spec)) => nil 
           (wf/reload (spec)) => nil 
           (instance-desc (get-spec :aws :endpoint) (get-spec :aws :instance-id))
             => (contains {:public-ip-address eip}) 
           (:machine (spec)) => (contains {:ip eip})
           (wf/destroy (spec)) => nil))

      (fact "aws with ebs volumes" :integration :ec2 :workflow
        (let [with-vol {:aws {:volumes [{:device "/dev/sdn" :size 10 :clear true :volume-type "standard" }]}}]
          (wf/create (spec with-vol)) => nil
          (wf/reload (spec with-vol)) => nil 
          (wf/destroy (spec with-vol)) => nil))

      (fact "aws with ephemeral volumes" :integration :ec2 :workflow
        (let [with-vol {:aws {:instance-type "m1.small" :block-devices [{:device-name "/dev/sdb" :virtual-name "ephemeral0" }]}}]
          (wf/create (spec with-vol)) => nil
          (wf/reload (spec with-vol)) => nil 
          (wf/destroy (spec with-vol)) => nil))

      (fact "aws with zone and groups" :integration :ec2 :workflow
        (let [with-zone {:aws {:availability-zone "eu-west-1a" :security-groups ["test"]}} ]
          (wf/create (spec with-zone)) => nil
          (let [{:keys [placement security-groups]} 
                (instance-desc (get-spec :aws :endpoint) 
                               (get-spec :aws :instance-id))]
            placement  => (contains {:availability-zone "eu-west-1a"})
            (first security-groups) => (contains {:group-name "Test"}))
          (wf/reload (spec with-zone)) => nil 
          (wf/destroy (spec with-zone)) => nil))

      (fact "aws puppetization" :integration :ec2 :workflow
          (wf/create (spec)) => nil
          (wf/provision redis-type (spec)) => nil 
          (wf/destroy (spec)) => nil)

{'fraction_non_alphanumeric': 0.1628424256614376, 'fraction_numerical': 0.006321704518848045, 'mean_word_length': 2.2794625719769672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1681246', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2687, 'n_words': 720}