Class: ModuleInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/module_installer.rb

Instance Method Summary collapse

Instance Method Details

#install_module(module_name_or_path, module_version = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/module_installer.rb', line 7

def install_module(module_name_or_path, module_version = nil)
  brpm_content_spec = nil

  if true #TODO: support no-gem-install mode
    module_spec, specs = install_gem(module_name_or_path, module_version)

    brpm_content_spec = specs.find { |spec| spec.name == "brpm_content_framework" } if specs

    install_bundle(module_spec)
  else
    module_name = module_name_or_path
    module_spec = Gem::Specification.find_by_name(module_name)
  end

  if BrpmAuto.brpm_installed?
    BrpmAuto.log "A BRPM instance is installed locally"

    if brpm_content_spec
      if brpm_content_spec.version > Gem::Version.new(BrpmAuto.version) or ! File.exist?(get_symlink_path)
        BrpmAuto.log "Updating the symlink to brpm_content_framework-latest..."
        update_symlink_to_brpm_content(brpm_content_spec.gem_dir)
      end

      if brpm_content_spec.version > Gem::Version.new(BrpmAuto.version) or ! File.exist?("#{ENV["BRPM_HOME"]}/automation_results/log.html")
        BrpmAuto.log "Copying the log.html file to te automation_results directory..."
        FileUtils.cp("#{brpm_content_spec.gem_dir}/infrastructure/log.html", "#{ENV["BRPM_HOME"]}/automation_results")
      end
    end

    BrpmAuto.log "Preparing the connectivity to BRPM..."
    if prepare_brpm_connection
      module_friendly_name = get_module_friendly_name(module_spec)
      BrpmAuto.log "Creating an automation category for #{module_friendly_name} if one doesn't exist yet..."
      create_automation_category_if_not_exists(module_friendly_name)

      BrpmAuto.log "Retrieving the integration servers..."
      integration_servers = @brpm_rest_client.get_project_servers

      BrpmAuto.log "Installing the automation script wrappers in the local BRPM instance..."
      failed_scripts = each_auto_script_wrapper(module_spec.gem_dir) do |auto_script_path, automation_type|
        BrpmAuto.log "Installing automation script wrapper for script #{auto_script_path}..."
        install_auto_script_wrapper(auto_script_path, automation_type, module_spec.name, module_friendly_name, integration_servers)
      end

      if failed_scripts.size > 0
        return false
      end
    end
  end
end

#uninstall_module(module_name, module_version) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/module_installer.rb', line 58

def uninstall_module(module_name, module_version)
  if BrpmAuto.brpm_installed?
    BrpmAuto.log "A BRPM instance is installed locally"

    BrpmAuto.log "Preparing the connectivity to BRPM..."
    if prepare_brpm_connection
      version_req = Gem::Requirement.create(Gem::Version.new(module_version))
      module_spec = Gem::Specification.find_by_name(module_name, version_req)

      module_friendly_name = get_module_friendly_name(module_spec)

      BrpmAuto.log "Uninstalling the automation script wrappers in the local BRPM instance..."
      failed_scripts = each_auto_script_wrapper(module_spec.gem_dir) do |auto_script_path, _|
        BrpmAuto.log "Uninstalling automation script wrapper for script #{auto_script_path}..."
        uninstall_auto_script_wrapper(auto_script_path, module_friendly_name)
      end

      if failed_scripts.size > 0
        BrpmAuto.log "Aborting the uninstall."
        return false
      end

      BrpmAuto.log "Deleting the automation category for #{module_friendly_name}..."
      delete_automation_category(module_friendly_name)
    end
  end

  BrpmAuto.log "Uninstalling gem #{module_name} #{module_version}..."
  BrpmAuto.log `gem uninstall #{module_name} -v #{module_version} -x`

  true
end