diff --git a/app/presenters/tree_node_builder.rb b/app/presenters/tree_node_builder.rb index 65890c10f96..e27928cee33 100644 --- a/app/presenters/tree_node_builder.rb +++ b/app/presenters/tree_node_builder.rb @@ -50,14 +50,14 @@ def build_id # rubocop:disable LineLength, Style/BlockDelimiters, Style/BlockEndNewline # rubocop:disable Style/Lambda, Style/AlignParameters, Style/MultilineBlockLayout BUILD_NODE_HASH = { - "AssignedServerRole" => -> { assigned_server_role_node(object) }, - "AvailabilityZone" => -> { generic_node(object.name, + "AssignedServerRole" => -> { assigned_server_role_node(object) }, + "AvailabilityZone" => -> { generic_node(object.name, "availability_zone.png", _("Availability Zone: %{name}") % {:name => object.name}) }, - "ConfigurationScript" => -> { generic_node(object.name, + "ConfigurationScript" => -> { generic_node(object.name, "configuration_script.png", "Ansible Tower Job Template: #{object.name}") }, - "ExtManagementSystem" => -> { + "ExtManagementSystem" => -> { # TODO: This should really leverage .base_model on an EMS prefix_model = case object @@ -67,105 +67,100 @@ def build_id end generic_node(object.name, "vendor-#{object.image_name}.png", "#{ui_lookup(:model => prefix_model)}: #{object.name}") }, - "ChargebackRate" => -> { generic_node(object.description, "chargeback_rate.png") }, - "Classification" => -> { classification_node }, - "Compliance" => -> { + "ChargebackRate" => -> { generic_node(object.description, "chargeback_rate.png") }, + "Classification" => -> { classification_node }, + "Compliance" => -> { name = "" + _("Compliance Check on: ") + "" + format_timezone(object.timestamp, Time.zone, 'gtl') generic_node(name.html_safe, "#{object.compliant ? "check" : "x"}.png") }, - "ComplianceDetail" => -> { + "ComplianceDetail" => -> { name = "" + _("Policy: ") + "" + object.miq_policy_desc generic_node(name.html_safe, "#{object.miq_policy_result ? "check" : "x"}.png") }, - "Condition" => -> { generic_node(object.description, "miq_condition.png") }, - "ConfigurationProfile" => -> { configuration_profile_node(object.name, "configuration_profile.png", + "Condition" => -> { generic_node(object.description, "miq_condition.png") }, + "ConfigurationProfile" => -> { configuration_profile_node(object.name, "configuration_profile.png", _("Configuration Profile: %{name}") % {:name => object.name}) }, - "ConfiguredSystem" => -> { generic_node(object.hostname, + "ConfiguredSystem" => -> { generic_node(object.hostname, "configured_system.png", _("Configured System: %{hostname}") % {:hostname => object.hostname}) }, - "Container" => -> { generic_node(object.name, "container.png") }, - "CustomButton" => -> { generic_node(object.name, + "Container" => -> { generic_node(object.name, "container.png") }, + "CustomButton" => -> { generic_node(object.name, object.options && object.options[:button_image] ? "custom-#{object.options[:button_image]}.png" : "leaf.gif", _("Button: %{button_description}") % {:button_description => object.description}) }, - "CustomButtonSet" => -> { custom_button_set_node }, - "CustomizationTemplate" => -> { generic_node(object.name, "customizationtemplate.png") }, - "Dialog" => -> { generic_node(object.label, "dialog.png") }, - "DialogTab" => -> { generic_node(object.label, "dialog_tab.png") }, - "DialogGroup" => -> { generic_node(object.label, "dialog_group.png") }, - "DialogField" => -> { generic_node(object.label, "dialog_field.png") }, - "EmsFolder" => -> { ems_folder_node }, - "EmsCluster" => -> { generic_node(object.name, "cluster.png", "#{ui_lookup(:table => "ems_cluster")}: #{object.name}") }, - "GuestDevice" => -> { guest_node(object) }, - "Host" => -> { generic_node(object.name, + "CustomButtonSet" => -> { custom_button_set_node }, + "CustomizationTemplate" => -> { generic_node(object.name, "customizationtemplate.png") }, + "Dialog" => -> { generic_node(object.label, "dialog.png") }, + "DialogTab" => -> { generic_node(object.label, "dialog_tab.png") }, + "DialogGroup" => -> { generic_node(object.label, "dialog_group.png") }, + "DialogField" => -> { generic_node(object.label, "dialog_field.png") }, + "EmsFolder" => -> { ems_folder_node }, + "EmsCluster" => -> { generic_node(object.name, "cluster.png", "#{ui_lookup(:table => "ems_cluster")}: #{object.name}") }, + "GuestDevice" => -> { guest_node(object) }, + "Host" => -> { generic_node(object.name, "host.png", "#{ui_lookup(:table => "host")}: #{object.name}") }, - "IsoDatastore" => -> { generic_node(object.name, "isodatastore.png") }, - "IsoImage" => -> { generic_node(object.name, "isoimage.png") }, - "ResourcePool" => -> { generic_node(object.name, object.vapp ? "vapp.png" : "resource_pool.png") }, + "IsoDatastore" => -> { generic_node(object.name, "isodatastore.png") }, + "IsoImage" => -> { generic_node(object.name, "isoimage.png") }, + "ResourcePool" => -> { generic_node(object.name, object.vapp ? "vapp.png" : "resource_pool.png") }, - "Vm" => -> { vm_node(object) }, - "Lan" => -> { generic_node(object.name, + "Lan" => -> { generic_node(object.name, "lan.png", _("Port Group: %{name}") % {:name => object.name}) }, - "LdapDomain" => -> { generic_node(_("Domain: %{domain_name}") % {:domain_name => object.name}, + "LdapDomain" => -> { generic_node(_("Domain: %{domain_name}") % {:domain_name => object.name}, "ldap_domain.png", _("LDAP Domain: %{ldap_domain_name}") % {:ldap_domain_name => object.name}) }, - "LdapRegion" => -> { generic_node(_("Region: %{region_name}") % {:region_name => object.name}, + "LdapRegion" => -> { generic_node(_("Region: %{region_name}") % {:region_name => object.name}, "ldap_region.png", _("LDAP Region: %{ldap_region_name}") % {:ldap_region_name => object.name}) }, - "MiqAeClass" => -> { node_with_display_name("ae_class.png") }, - "MiqAeInstance" => -> { node_with_display_name("ae_instance.png") }, - "MiqAeMethod" => -> { node_with_display_name("ae_method.png") }, - "MiqAeNamespace" => -> { node_with_display_name("ae_namespace.png") }, - "MiqAlertSet" => -> { generic_node(object.description, "miq_alert_profile.png") }, - "MiqReport" => -> { generic_node(object.name, "report.png") }, - "MiqReportResult" => -> { miq_report_node(object.last_run_on, object.name, object.status) }, - "MiqSchedule" => -> { generic_node(object.name, "miq_schedule.png") }, - "MiqScsiLun" => -> { generic_node(object.canonical_name, + "MiqAeClass" => -> { node_with_display_name("ae_class.png") }, + "MiqAeInstance" => -> { node_with_display_name("ae_instance.png") }, + "MiqAeMethod" => -> { node_with_display_name("ae_method.png") }, + "MiqAeNamespace" => -> { node_with_display_name("ae_namespace.png") }, + "MiqAlertSet" => -> { generic_node(object.description, "miq_alert_profile.png") }, + "MiqReport" => -> { generic_node(object.name, "report.png") }, + "MiqReportResult" => -> { miq_report_node(object.last_run_on, object.name, object.status) }, + "MiqSchedule" => -> { generic_node(object.name, "miq_schedule.png") }, + "MiqScsiLun" => -> { generic_node(object.canonical_name, "lun.png", _("LUN: %{name}") % {:name => object.canonical_name}) }, - "MiqScsiTarget" => -> { miq_scsi_target(object.iscsi_name, object.target) }, - "MiqServer" => -> { miq_server_node }, - "MiqAlert" => -> { generic_node(object.description, "miq_alert.png") }, - "MiqAction" => -> { miq_action_node }, - "MiqEventDefinition" => -> { generic_node(object.description, "event-#{object.name}.png") }, - "MiqGroup" => -> { generic_node(object.name, "group.png") }, + "MiqScsiTarget" => -> { miq_scsi_target(object.iscsi_name, object.target) }, + "MiqServer" => -> { miq_server_node }, + "MiqAlert" => -> { generic_node(object.description, "miq_alert.png") }, + "MiqAction" => -> { miq_action_node }, + "MiqEventDefinition" => -> { generic_node(object.description, "event-#{object.name}.png") }, + "MiqGroup" => -> { generic_node(object.name, "group.png") }, # Following line has dynatree workaround, add class to allow clicking on bold portion of title. - "MiqPolicy" => -> { miq_policy_node }, - "MiqPolicySet" => -> { generic_node(object.description, "policy_profile#{object.active? ? "" : "_inactive"}.png") }, - "MiqUserRole" => -> { generic_node(object.name, "miq_user_role.png") }, - "OrchestrationTemplateCfn" => -> { generic_node(object.name, "orchestration_template_cfn.png") }, - "OrchestrationTemplateHot" => -> { generic_node(object.name, "orchestration_template_hot.png") }, - "OrchestrationTemplateAzure" => -> { generic_node(object.name, "orchestration_template_azure.png") }, - "OrchestrationTemplateVnfd" => -> { generic_node(object.name, "orchestration_template_vnfd.png") }, - "OrchestrationTemplate" => -> { generic_node(object.name, "orchestration_template_vapp.png") }, - "PxeImage" => -> { generic_node(object.name, object.default_for_windows ? "win32service.png" : "pxeimage.png") }, - "WindowsImage" => -> { generic_node(object.name, "os-windows_generic.png") }, - "PxeImageType" => -> { generic_node(object.name, "pxeimagetype.png") }, - "PxeServer" => -> { generic_node(object.name, "pxeserver.png") }, - "ScanItemSet" => -> { generic_node(object.name, "scan_item_set.png") }, - "Service" => -> { generic_node(object.name, object.picture ? "/pictures/#{object.picture.basename}" : "service.png") }, - "ServiceResource" => -> { generic_node(object.resource_name, object.resource_type == "VmOrTemplate" ? "vm.png" : "service_template.png") }, - "ServerRole" => -> { server_role_node(object) }, - "ServiceTemplate" => -> { service_template_node }, - "ServiceTemplateCatalog" => -> { service_template_catalog_node }, - "Snapshot" => -> { snapshot_node }, - "Storage" => -> { generic_node(object.name, "storage.png") }, - "Switch" => -> { generic_node(object.name, + "MiqPolicy" => -> { miq_policy_node }, + "MiqPolicySet" => -> { generic_node(object.description, "policy_profile#{object.active? ? "" : "_inactive"}.png") }, + "MiqUserRole" => -> { generic_node(object.name, "miq_user_role.png") }, + "OrchestrationTemplate" => -> { orchestration_template_node }, + "PxeImage" => -> { generic_node(object.name, object.default_for_windows ? "win32service.png" : "pxeimage.png") }, + "WindowsImage" => -> { generic_node(object.name, "os-windows_generic.png") }, + "PxeImageType" => -> { generic_node(object.name, "pxeimagetype.png") }, + "PxeServer" => -> { generic_node(object.name, "pxeserver.png") }, + "ScanItemSet" => -> { generic_node(object.name, "scan_item_set.png") }, + "Service" => -> { generic_node(object.name, object.picture ? "/pictures/#{object.picture.basename}" : "service.png") }, + "ServiceResource" => -> { generic_node(object.resource_name, object.resource_type == "VmOrTemplate" ? "vm.png" : "service_template.png") }, + "ServerRole" => -> { server_role_node(object) }, + "ServiceTemplate" => -> { service_template_node }, + "ServiceTemplateCatalog" => -> { service_template_catalog_node }, + "Snapshot" => -> { snapshot_node }, + "Storage" => -> { generic_node(object.name, "storage.png") }, + "Switch" => -> { generic_node(object.name, "switch.png", _("Switch: %{name}") % {:name => object.name}) }, - "User" => -> { generic_node(object.name, "user.png") }, - "MiqSearch" => -> { generic_node(object.description, + "User" => -> { generic_node(object.name, "user.png") }, + "MiqSearch" => -> { generic_node(object.description, "filter.png", _("Filter: %{filter_description}") % {:filter_description => object.description}) }, - "MiqDialog" => -> { generic_node(object.description, "miqdialog.png", object[0]) }, - "MiqRegion" => -> { miq_region_node }, - "MiqWidget" => -> { generic_node(object.title, "#{object.content_type}_widget.png", object.title) }, - "MiqWidgetSet" => -> { generic_node(object.name, "dashboard.png", object.name) }, - "Tenant" => -> { generic_node(object.name, "#{object.tenant? ? "tenant" : "project"}.png") }, - "VmdbTableEvm" => -> { generic_node(object.name, "vmdbtableevm.png") }, - "VmdbIndex" => -> { generic_node(object.name, "vmdbindex.png") }, - "VmOrTemplate" => -> { generic_node(object.name, "currentstate-#{object.normalized_state.downcase}.png") }, - "Zone" => -> { zone_node }, - "Hash" => -> { hash_node }, + "MiqDialog" => -> { generic_node(object.description, "miqdialog.png", object[0]) }, + "MiqRegion" => -> { miq_region_node }, + "MiqWidget" => -> { generic_node(object.title, "#{object.content_type}_widget.png", object.title) }, + "MiqWidgetSet" => -> { generic_node(object.name, "dashboard.png", object.name) }, + "Tenant" => -> { generic_node(object.name, "#{object.tenant? ? "tenant" : "project"}.png") }, + "VmdbTable" => -> { generic_node(object.name, "vmdbtableevm.png") }, + "VmdbIndex" => -> { generic_node(object.name, "vmdbindex.png") }, + "VmOrTemplate" => -> { vm_node(object) }, + "Zone" => -> { zone_node }, + "Hash" => -> { hash_node }, }.freeze # rubocop:enable all @@ -174,9 +169,9 @@ def build # to lookup based on that. obj = object.kind_of?(Draper::Decorator) ? object.object : object - # Find the proc for the class either based on it's non-namespaced class - # name, or it's `base_class` (the top level of the inheritence tree) - node_lambda = BUILD_NODE_HASH[obj.class.to_s.split("::").last] + # Find the proc for the class either based on it's class name, or it's + # `base_class` (the top level of the inheritence tree) + node_lambda = BUILD_NODE_HASH[obj.class.name] node_lambda ||= BUILD_NODE_HASH[obj.class.base_class.to_s] # Execute the proc from the BUILD_NODE_HASH in the context of the instance @@ -315,10 +310,10 @@ def configuration_profile_node(text, image, tip = nil) def vm_node(object) image = "currentstate-#{object.normalized_state.downcase}.png" - if object.template? - image = object.host ? "template.png" : "template-no-host.png" + unless object.template? + tip = _("VM: %{name} (Click to view)") % {:name => object.name} end - generic_node(object.name, image, _("VM: %{name} (Click to view)") % {:name => object.name}) + generic_node(object.name, image, tip) end def image_for_node(object, image) @@ -461,6 +456,12 @@ def miq_policy_node generic_node(text, image) end + def orchestration_template_node + image_suffix = "_%s" % object.class.name.underscore.split("_").last.downcase + image_suffix = "_vapp" if image_suffix == "_template" + generic_node(object.name, "orchestration_template#{image_suffix}.png") + end + def format_parent_id (options[:full_ids] && !parent_id.blank?) ? "#{parent_id}_" : '' end diff --git a/app/presenters/tree_node_builder_datacenter.rb b/app/presenters/tree_node_builder_datacenter.rb index 1a70baf8045..041f7068812 100644 --- a/app/presenters/tree_node_builder_datacenter.rb +++ b/app/presenters/tree_node_builder_datacenter.rb @@ -33,9 +33,9 @@ def normal_folder_node def vm_node(object) image = "currentstate-#{object.normalized_state.downcase}.png" - if object.template? - image = object.host ? "template.png" : "template-no-host.png" + unless object.template? + tip = _("VM: %{name}") % {:name => object.name} end - generic_node(object.name, image, _("VM: %{name}") % {:name => object.name}) + generic_node(object.name, image, tip) end end diff --git a/spec/factories/availability_zone.rb b/spec/factories/availability_zone.rb index 22ab58c2938..32710f014ab 100644 --- a/spec/factories/availability_zone.rb +++ b/spec/factories/availability_zone.rb @@ -6,6 +6,10 @@ factory :availability_zone_amazon, :parent => :availability_zone, :class => "ManageIQ::Providers::Amazon::CloudManager::AvailabilityZone" do end + factory :availability_zone_azure, + :parent => :availability_zone, + :class => "ManageIQ::Providers::Azure::CloudManager::AvailabilityZone" + factory :availability_zone_openstack, :parent => :availability_zone, :class => "ManageIQ::Providers::Openstack::CloudManager::AvailabilityZone" do end @@ -15,6 +19,10 @@ factory :availability_zone_google, :parent => :availability_zone, :class => "ManageIQ::Providers::Google::CloudManager::AvailabilityZone" do end + factory :availability_zone_vmware, + :parent => :availability_zone, + :class => "ManageIQ::Providers::Vmware::CloudManager::AvailabilityZone" + factory :availability_zone_target, :parent => :availability_zone do after(:create) do |x| x.perf_capture_enabled = true diff --git a/spec/factories/configuration_profile.rb b/spec/factories/configuration_profile.rb index cdee2c76b49..c49d8578e87 100644 --- a/spec/factories/configuration_profile.rb +++ b/spec/factories/configuration_profile.rb @@ -1 +1,10 @@ -FactoryGirl.define { factory :configuration_profile } +FactoryGirl.define do + factory :configuration_profile + + factory :configuration_profile_forman, + :aliases => ["manageiq/providers/foreman/configuration_manager/configuration_profile"], + :class => "ManageIQ::Providers::Foreman::ConfigurationManager::ConfigurationProfile", + :parent => :configuration_profile do + name "foreman config profile" + end +end diff --git a/spec/factories/configured_system.rb b/spec/factories/configured_system.rb index 54a3bad524e..eb91e76bc02 100644 --- a/spec/factories/configured_system.rb +++ b/spec/factories/configured_system.rb @@ -2,4 +2,12 @@ factory :configured_system do sequence(:name) { |n| "Configured_system_#{seq_padded_for_sorting(n)}" } end + + factory :configured_system_foreman, + :class => "ManageIQ::Providers::Foreman::ConfigurationManager::ConfiguredSystem", + :parent => :configured_system + + factory :configured_system_ansible_tower, + :class => "ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfiguredSystem", + :parent => :configured_system end diff --git a/spec/factories/configured_system_foreman.rb b/spec/factories/configured_system_foreman.rb deleted file mode 100644 index c1afa1b2a68..00000000000 --- a/spec/factories/configured_system_foreman.rb +++ /dev/null @@ -1 +0,0 @@ -FactoryGirl.define { factory :configured_system_foreman, :class => "ManageIQ::Providers::Foreman::ConfigurationManager::ConfiguredSystem", :parent => :configured_system } diff --git a/spec/factories/customization_template.rb b/spec/factories/customization_template.rb index 9613f08459c..1afb5d57d9f 100644 --- a/spec/factories/customization_template.rb +++ b/spec/factories/customization_template.rb @@ -6,4 +6,26 @@ x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) end end + + factory :customization_template_cloud_init do + after(:build) do |x| + x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) + end + end + + factory :customization_template_kickstart do + sequence(:name) { |n| "customization_template_kickstart_#{seq_padded_for_sorting(n)}" } + sequence(:description) { |n| "Customization Template Kickstart #{seq_padded_for_sorting(n)}" } + after(:build) do |x| + x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) + end + end + + factory :customization_template_sysprep do + sequence(:name) { |n| "customization_template_syspre_#{seq_padded_for_sorting(n)}" } + sequence(:description) { |n| "Customization Template Sysprep #{seq_padded_for_sorting(n)}" } + after(:build) do |x| + x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) + end + end end diff --git a/spec/factories/customization_template_cloud_init.rb b/spec/factories/customization_template_cloud_init.rb deleted file mode 100644 index 6389d39d5f5..00000000000 --- a/spec/factories/customization_template_cloud_init.rb +++ /dev/null @@ -1,7 +0,0 @@ -FactoryGirl.define do - factory :customization_template_cloud_init do - after(:build) do |x| - x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) - end - end -end diff --git a/spec/factories/customization_template_kickstart.rb b/spec/factories/customization_template_kickstart.rb deleted file mode 100644 index 3f923becf1d..00000000000 --- a/spec/factories/customization_template_kickstart.rb +++ /dev/null @@ -1,9 +0,0 @@ -FactoryGirl.define do - factory :customization_template_kickstart do - sequence(:name) { |n| "customization_template_kickstart_#{seq_padded_for_sorting(n)}" } - sequence(:description) { |n| "Customization Template Kickstart #{seq_padded_for_sorting(n)}" } - after(:build) do |x| - x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) - end - end -end diff --git a/spec/factories/ems_folder.rb b/spec/factories/ems_folder.rb index b3c2b3c6aeb..6e34abc9567 100644 --- a/spec/factories/ems_folder.rb +++ b/spec/factories/ems_folder.rb @@ -6,4 +6,12 @@ factory :datacenter, :parent => :ems_folder, :class => "Datacenter" factory :storage_cluster, :parent => :ems_folder, :class => "StorageCluster" + + factory :inventory_group, + :class => "ManageIQ::Providers::ConfigurationManager::InventoryGroup", + :parent => :ems_folder + + factory :inventory_root_group, + :class => "ManageIQ::Providers::ConfigurationManager::InventoryRootGroup", + :parent => :ems_folder end diff --git a/spec/factories/ext_management_system.rb b/spec/factories/ext_management_system.rb index ba2fb95f7a2..184645025db 100644 --- a/spec/factories/ext_management_system.rb +++ b/spec/factories/ext_management_system.rb @@ -196,6 +196,27 @@ end end + factory :ems_azure, + :aliases => ["manageiq/providers/azure/cloud_manager"], + :class => "ManageIQ::Providers::Azure::CloudManager", + :parent => :ems_cloud do + end + + factory :ems_azure_network, + :aliases => ["manageiq/providers/azure/network_manager"], + :class => "ManageIQ::Providers::Azure::NetworkManager", + :parent => :ems_network do + end + + factory :ems_azure_with_authentication, + :parent => :ems_azure do + azure_tenant_id "ABCDEFGHIJABCDEFGHIJ0123456789AB" + subscription "0123456789ABCDEFGHIJABCDEFGHIJKL" + after :create do |x| + x.authentications << FactoryGirl.create(:authentication) + end + end + factory :ems_openstack, :aliases => ["manageiq/providers/openstack/cloud_manager"], :class => "ManageIQ::Providers::Openstack::CloudManager", @@ -316,21 +337,6 @@ end end - factory :ems_azure, - :aliases => ["manageiq/providers/azure/cloud_manager"], - :class => "ManageIQ::Providers::Azure::CloudManager", - :parent => :ems_cloud do - end - - factory :ems_azure_with_authentication, - :parent => :ems_azure do - azure_tenant_id "ABCDEFGHIJABCDEFGHIJ0123456789AB" - subscription "0123456789ABCDEFGHIJABCDEFGHIJKL" - after :create do |x| - x.authentications << FactoryGirl.create(:authentication) - end - end - # Leaf classes for middleware_manager factory :ems_hawkular, diff --git a/spec/factories/template_vmware_cloud.rb b/spec/factories/template_vmware_cloud.rb new file mode 100644 index 00000000000..679dde72bae --- /dev/null +++ b/spec/factories/template_vmware_cloud.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :template_vmware_cloud, + :class => "ManageIQ::Providers::Vmware::CloudManager::Template", + :parent => :template_cloud do + vendor "vmware" + end +end diff --git a/spec/factories/vm_or_template.rb b/spec/factories/vm_or_template.rb index 717c63b2403..e3ce1c72f6e 100644 --- a/spec/factories/vm_or_template.rb +++ b/spec/factories/vm_or_template.rb @@ -17,6 +17,8 @@ factory(:vm, :class => "Vm", :parent => :vm_or_template) factory(:vm_cloud, :class => "VmCloud", :parent => :vm) { cloud true } factory(:vm_infra, :class => "VmInfra", :parent => :vm) + factory(:vm_server, :class => "VmServer", :parent => :vm) + factory(:vm_xen, :class => "VmXen", :parent => :vm_infra) factory(:template_cloud, :class => "TemplateCloud", :parent => :template) { cloud true } factory(:template_infra, :class => "TemplateInfra", :parent => :template) @@ -28,4 +30,6 @@ location { |x| "#{x.name}/#{x.name}.img.manifest.xml" } vendor "amazon" end + + factory(:template_xen, :class => "TemplateXen", :parent => :template_infra) end diff --git a/spec/presenters/tree_node_builder_spec.rb b/spec/presenters/tree_node_builder_spec.rb index 229684467d7..9e9f2c70d84 100644 --- a/spec/presenters/tree_node_builder_spec.rb +++ b/spec/presenters/tree_node_builder_spec.rb @@ -1,21 +1,285 @@ describe TreeNodeBuilder do + # Stub .image_path to just return what was sent to it + before(:each) do + allow(ActionController::Base.helpers).to receive(:image_path) do |img| + img + end + end + + def compress_id(id) + ApplicationRecord.compress_id(id) + end + context '.build' do - it 'ExtManagementSystem node' do - mgmt_system = FactoryGirl.build(:ems_redhat) - node = TreeNodeBuilder.build(mgmt_system, nil, {}) - expect(node).not_to be_nil + context 'AvailabilityZone node' do + %w(amazon azure google openstack openstack_null vmware).each do |az_type| + it az_type.split("_").map(&:capitalize).join(' ') do + zone = FactoryGirl.build("availability_zone_#{az_type}") + node = TreeNodeBuilder.build(zone, nil, {}) + expect(node).to eq( + :key => "-#{zone.name}", + :title => zone.name, + :icon => "100/availability_zone.png", + :tooltip => "Availability Zone: #{zone.name}", + :expand => false + ) + end + end + end + + it 'ConfigurationScript node' do + config_script = FactoryGirl.build(:ansible_configuration_script) + node = TreeNodeBuilder.build(config_script, nil, {}) + expect(node).to eq( + :key => "-#{config_script.name}", + :title => config_script.name, + :icon => "100/configuration_script.png", + :tooltip => "Ansible Tower Job Template: #{config_script.name}", + :expand => false + ) end - it 'AvailabilityZone node' do - zone = FactoryGirl.build(:availability_zone_amazon) - node = TreeNodeBuilder.build(zone, nil, {}) - expect(node).not_to be_nil + context 'ExtManagementSystem node' do + # EmsInfra + %w(microsoft openstack_infra redhat vmware).each do |provider| + it "#{provider.gsub('_infra', '').capitalize} EmsInfra" do + mgmt_system = FactoryGirl.build("ems_#{provider}") + node = TreeNodeBuilder.build(mgmt_system, nil, {}) + expect(node).to eq( + :key => "-#{mgmt_system.name}", + :title => mgmt_system.name, + :icon => "100/vendor-#{mgmt_system.image_name}.png", + :tooltip => "Ems Infra: #{mgmt_system.name}", + :expand => false + ) + end + end + + # EmsCloud + %w(amazon azure google openstack vmware_cloud).each do |provider| + it "#{provider.gsub('_cloud', '').capitalize} EmsCloud" do + mgmt_system = FactoryGirl.build("ems_#{provider}") + node = TreeNodeBuilder.build(mgmt_system, nil, {}) + expect(node).to eq( + :key => "-#{mgmt_system.name}", + :title => mgmt_system.name, + :icon => "100/vendor-#{mgmt_system.image_name}.png", + :tooltip => "Ems Cloud: #{mgmt_system.name}", + :expand => false + ) + end + end + + # All the other ExtManagementSystem classes... + { + # :configuration_manager => "ConfigurationManager", + # :provisioning_manager => "ProvisioningManager", + # :ems_cloud => "CloudManager", + # :ems_container => "ContainerManager", + # :ems_infra => "InfraManager", + # :ems_middleware => "MiddlewareManager", + # :ems_network => "NetworkManager", + # :ems_storage => "StorageManager", + :configuration_manager_ansible_tower => "AnsibleTower ConfigurationManager", + :configuration_manager_foreman => "Foreman ConfigurationManager", + :provisioning_manager_foreman => "Foreman ProvisioningManager", + :ems_physical_infra => "PhysicalInfraManager", + :ems_openshift_enterprise => "Openshift Enterprise ContainerManager", + :ems_hawkular => "Hawkular MiddlewareManager", + :ems_azure_network => "Azure NetworkManager", + :ems_amazon_network => "Amazon NetworkManager", + :ems_google_network => "Google NetworkManager", + :ems_nuage_network => "Nuage NetworkManager", + :ems_openstack_network => "Openstack NetworkManager", + :ems_vmware_cloud_network => "Vmware NetworkManager", + :ems_cinder => "CinderManager StorageManager", + :ems_swift => "SwiftManager StorageManager" + }.each do |factory, ems_name| + it "#{ems_name} ExtManagementSystem" do + mgmt_system = FactoryGirl.build(factory) + node = TreeNodeBuilder.build(mgmt_system, nil, {}) + expect(node).to eq( + :key => "-#{mgmt_system.name}", + :title => mgmt_system.name, + :icon => "100/vendor-#{mgmt_system.image_name}.png", + :tooltip => "Provider: #{mgmt_system.name}", + :expand => false + ) + end + end end it 'ChargebackRate node' do rate = FactoryGirl.create(:chargeback_rate) node = TreeNodeBuilder.build(rate, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "cr-#{compress_id(rate.id)}", + :title => rate.description, + :icon => "100/chargeback_rate.png", + :expand => false + ) + end + + context "Classification node" do + it "Regular" do + classification = FactoryGirl.build(:classification) + node = TreeNodeBuilder.build(classification, nil, {}) + expect(node).to eq( + :key => "-#{classification.name}", + :title => classification.description, + :icon => "100/folder", # is this a bug? + :tooltip => "Category: #{classification.description}", + :expand => false, + :cfmeNoClick => true, + :hideCheckbox => true + ) + end + + it "Category" do + category = FactoryGirl.build(:category) + node = TreeNodeBuilder.build(category, nil, {}) + expect(node).to eq( + :key => "-#{category.name}", + :title => category.description, + :icon => "100/folder", # is this a bug? + :tooltip => "Category: #{category.description}", + :expand => false, + :cfmeNoClick => true, + :hideCheckbox => true + ) + end + end + + context "Compliance node" do + it "passed compliance" do + compliance = FactoryGirl.create(:compliance, :compliant => true) + node = TreeNodeBuilder.build(compliance, nil, {}) + expect(node).to eq( + :key => "cm-#{compress_id(compliance.id)}", + :title => "Compliance Check on: #{compliance.timestamp}", + :icon => "100/check.png", + :expand => false + ) + end + + it "failed compliance" do + compliance = FactoryGirl.create(:compliance, :compliant => false) + node = TreeNodeBuilder.build(compliance, nil, {}) + expect(node).to eq( + :key => "cm-#{compress_id(compliance.id)}", + :title => "Compliance Check on: #{compliance.timestamp}", + :icon => "100/x.png", + :expand => false + ) + end + end + + context "ComplianceDetail" do + it "passed compliance" do + compliance = FactoryGirl.create(:compliance_detail, :miq_policy_result => true) + node = TreeNodeBuilder.build(compliance, nil, {}) + expect(node).to eq( + :key => "cd-#{compress_id(compliance.id)}", + :title => "Policy: #{compliance.miq_policy_desc}", + :icon => "100/check.png", + :expand => false + ) + end + + it "failed compliance" do + compliance = FactoryGirl.create(:compliance_detail, :miq_policy_result => false) + node = TreeNodeBuilder.build(compliance, nil, {}) + expect(node).to eq( + :key => "cd-#{compress_id(compliance.id)}", + :title => "Policy: #{compliance.miq_policy_desc}", + :icon => "100/x.png", + :expand => false + ) + end + end + + it 'Condition node' do + condition = FactoryGirl.build(:condition) + node = TreeNodeBuilder.build(condition, nil, {}) + expect(node).to eq( + :key => "-#{condition.name}", + :title => condition.description, + :icon => "100/miq_condition.png", + :expand => false + ) + end + + it 'ConfigurationProfile node' do + config_profile = FactoryGirl.build(:configuration_profile_forman) + node = TreeNodeBuilder.build(config_profile, nil, {}) + expect(node).to eq( + :key => "-#{config_profile.name}", + :title => config_profile.name, + :icon => "100/configuration_profile.png", + :tooltip => "Configuration Profile: #{config_profile.name}" + ) + end + + context "ConfiguredSystem node" do + it "Base" do + configured_system = FactoryGirl.build(:configured_system, :hostname => 'foo') + node = TreeNodeBuilder.build(configured_system, nil, {}) + expect(node).to eq( + :key => "-#{configured_system.name}", + :title => configured_system.name, + :icon => "100/configured_system.png", + :tooltip => "Configured System: #{configured_system.hostname}", + :expand => false + ) + end + + it "AnsibleTower" do + configured_system = FactoryGirl.build(:configured_system_foreman, :hostname => 'foreman') + node = TreeNodeBuilder.build(configured_system, nil, {}) + expect(node).to eq( + :key => "-#{configured_system.name}", + :title => configured_system.name, + :icon => "100/configured_system.png", + :tooltip => "Configured System: #{configured_system.hostname}", + :expand => false + ) + end + + it "Foreman" do + configured_system = FactoryGirl.build(:configured_system_foreman, :hostname => 'foreman') + node = TreeNodeBuilder.build(configured_system, nil, {}) + expect(node).to eq( + :key => "-#{configured_system.name}", + :title => configured_system.name, + :icon => "100/configured_system.png", + :tooltip => "Configured System: #{configured_system.hostname}", + :expand => false + ) + end + end + + context "Container node" do + it "Generic" do + container = FactoryGirl.build(:container, :name => "bananas") + node = TreeNodeBuilder.build(container, nil, {}) + expect(node).to eq( + :key => "-#{container.name}", + :title => container.name, + :icon => "100/container.png", + :expand => false + ) + end + + it "Kubernetes" do + container = FactoryGirl.build(:kubernetes_container, :name => "monkeys") + node = TreeNodeBuilder.build(container, nil, {}) + expect(node).to eq( + :key => "-#{container.name}", + :title => container.name, + :icon => "100/container.png", + :expand => false + ) + end end it 'CustomButton node' do @@ -24,132 +288,270 @@ :applies_to_id => nil, ) node = TreeNodeBuilder.build(button, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{button.name}", + :title => button.name, + :icon => "100/leaf.gif", + :tooltip => "Button: #{button.description}", + :expand => false + ) end it 'CustomButtonSet node' do button_set = FactoryGirl.build(:custom_button_set) node = TreeNodeBuilder.build(button_set, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{button_set.name}", + :title => button_set.name, + :icon => "100/folder.png", + :tooltip => "Button Group: #{button_set.description}", + :expand => false + ) end - it 'CustomizationTemplate node' do - template = FactoryGirl.build(:customization_template) - node = TreeNodeBuilder.build(template, nil, {}) - expect(node).not_to be_nil + context "CustomizationTemplate node" do + %w(base cloud_init kickstart sysprep).each do |ct| + it "CustomizationTemplate #{ct.classify}" do + factory = "customization_template_#{ct}".sub("_base", "") + template = FactoryGirl.build(factory, :name => ct) + node = TreeNodeBuilder.build(template, nil, {}) + expect(node).to eq( + :key => "-#{template.name}", + :title => template.name, + :icon => "100/customizationtemplate.png", + :expand => false + ) + end + end end it 'Dialog node' do dialog = FactoryGirl.build(:dialog, :label => 'How much wood would a woodchuck chuck if a woodchuck would chuck wood?') node = TreeNodeBuilder.build(dialog, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{dialog.name}", + :title => dialog.label, + :icon => "100/dialog.png", + :expand => false + ) end it 'DialogTab node' do tab = FactoryGirl.create(:dialog_tab, :label => '') node = TreeNodeBuilder.build(tab, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{compress_id(tab.id)}", + :title => ERB::Util.html_escape(tab.label), + :icon => "100/dialog_tab.png", + :expand => false + ) end it 'DialogGroup node' do group = FactoryGirl.create(:dialog_group, :label => ' foobar>') node = TreeNodeBuilder.build(group, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{compress_id(group.id)}", + :title => ERB::Util.html_escape(group.label), + :icon => "100/dialog_group.png", + :expand => false + ) end it 'DialogField node' do field = FactoryGirl.build(:dialog_field, :name => 'random field name', :label => 'foo') node = TreeNodeBuilder.build(field, nil, {}) - expect(node).not_to be_nil - end - - it 'EmsFolder node' do - folder = FactoryGirl.build(:ems_folder) - node = TreeNodeBuilder.build(folder, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{field.name}", + :title => field.label, + :icon => "100/dialog_field.png", + :expand => false + ) end - it 'valid EmsCluster node' do - cluster = FactoryGirl.create(:ems_cluster, :name => "My Cluster") - node = TreeNodeBuilder.build(cluster, nil, {}) - expect(node).not_to be_nil - - expect(node[:key]).to eq("c-#{MiqRegion.compress_id(cluster.id)}") - expect(node[:title]).to eq(cluster.name) - expect(node[:icon]).to eq(ActionController::Base.helpers.image_path('100/cluster.png')) - expect(node[:tooltip]).to eq("Cluster / Deployment Role: #{cluster.name}") + context "EmsFolder node" do + %w(ems_folder storage_cluster inventory_group inventory_root_group).each do |folder_type| + it folder_type.classify do + folder = FactoryGirl.build(folder_type) + node = TreeNodeBuilder.build(folder, nil, {}) + expect(node).to eq( + :key => "-#{folder.name}", + :title => folder.name, + :icon => "100/folder.png", + :tooltip => "Folder: #{folder.name}", + :expand => false + ) + end + end + + it "Datacenter" do + folder = FactoryGirl.build(:datacenter) + node = TreeNodeBuilder.build(folder, nil, {}) + expect(node).to eq( + :key => "-#{folder.name}", + :title => folder.name, + :icon => "100/datacenter.png", + :tooltip => "Datacenter: #{folder.name}", + :expand => false + ) + end + + it 'tooltip with %2f' do + ems_folder = FactoryGirl.create(:ems_folder, :name => 'foo %2f bar') + node = TreeNodeBuilder.build(ems_folder, nil, {}) + expect(node[:tooltip]).to eq('Folder: foo / bar') + end + end + + context "EmsCluster node" do + %w(ems_cluster ems_cluster_openstack).each do |ems_cluster| + it ems_cluster.classify do + cluster = FactoryGirl.create(ems_cluster, :name => "My Cluster") + node = TreeNodeBuilder.build(cluster, nil, {}) + expect(node).to eq( + :key => "c-#{compress_id(MiqRegion.compress_id(cluster.id))}", + :title => cluster.name, + :icon => "100/cluster.png", + :tooltip => "Cluster / Deployment Role: #{cluster.name}", + :expand => false + ) + end + end + end + + it "GuestDevice node" do + guest_device = FactoryGirl.create(:guest_device_nic) + node = TreeNodeBuilder.build(guest_device, nil, {}) + expect(node).to eq( + :key => "gd-#{compress_id(guest_device.id)}", + :title => guest_device.device_name, + :icon => "100/pnic.png", + :tooltip => "Physical NIC: #{guest_device.device_name}", + :expand => false + ) end - it 'valid Host Node' do - host = FactoryGirl.create(:host, :name => "My Host") - node = TreeNodeBuilder.build(host, nil, {}) - - expect(node[:key]).to eq("h-#{MiqRegion.compress_id(host.id)}") - expect(node[:title]).to eq(host.name) - expect(node[:icon]).to eq(ActionController::Base.helpers.image_path(('100/host.png'))) - expect(node[:tooltip]).to eq("Host / Node: #{host.name}") + context "Host node" do + %w(host host_microsoft host_redhat host_openstack_infra host_vmware host_vmware_esx).each do |host_factory| + it host_factory.sub("host_", "").classify do + host = FactoryGirl.create(host_factory, :name => "My Host") + node = TreeNodeBuilder.build(host, nil, {}) + expect(node).to eq( + :key => "h-#{compress_id(host.id)}", + :title => host.name, + :icon => "100/host.png", + :tooltip => "Host / Node: #{host.name}", + :expand => false + ) + end + end end it 'IsoDatastore node' do mgmt_system = FactoryGirl.build(:ems_redhat) datastore = FactoryGirl.build(:iso_datastore, :ext_management_system => mgmt_system) node = TreeNodeBuilder.build(datastore, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{datastore.name}", + :title => datastore.name, + :icon => "100/isodatastore.png", + :expand => false + ) end it 'IsoImage node' do image = FactoryGirl.create(:iso_image, :name => 'foo') node = TreeNodeBuilder.build(image, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "isi-#{compress_id(image.id)}", + :title => image.name, + :icon => "100/isoimage.png", + :expand => false + ) end it 'ResourcePool node' do pool = FactoryGirl.build(:resource_pool) node = TreeNodeBuilder.build(pool, nil, {}) - expect(node).not_to be_nil - end - - it 'Vm node' do - vm = FactoryGirl.build(:vm_amazon) - node = TreeNodeBuilder.build(vm, nil, {}) - expect(node).not_to be_nil - end - - it 'Vm node with /' do - vm = FactoryGirl.create(:vm_amazon, :name => 'foo / bar') - node = TreeNodeBuilder.build(vm, 'foo', {}) - expect(node[:title]).to eq('foo / bar') + expect(node).to eq( + :key => "-#{pool.name}", + :title => pool.name, + :icon => "100/resource_pool.png", + :expand => false + ) end - it 'Vm node with %2f' do - vm = FactoryGirl.create(:vm_amazon, :name => 'foo %2f bar') - node = TreeNodeBuilder.build(vm, nil, {}) - expect(node[:title]).to eq('foo / bar') + it "Lan node" do + lan = FactoryGirl.build(:lan) + node = TreeNodeBuilder.build(lan, nil, {}) + expect(node).to eq( + :key => "-#{lan.name}", + :title => lan.name, + :icon => "100/lan.png", + :tooltip => "Port Group: #{lan.name}", + :expand => false + ) end - it 'Vm node with tooltip' do - vm = FactoryGirl.create(:vm_amazon, :name => 'name') - node = TreeNodeBuilder.build(vm, nil, {}) - expect(node[:tooltip]).to eq(_("VM: %{name} (Click to view)") % {:name => vm.name}) + it "LdapDomain node" do + domain = FactoryGirl.build(:ldap_domain, :name => "ldap domain") + node = TreeNodeBuilder.build(domain, nil, {}) + expect(node).to eq( + :key => "-#{domain.name}", + :title => "Domain: #{domain.name}", + :icon => "100/ldap_domain.png", + :tooltip => "LDAP Domain: #{domain.name}", + :expand => false + ) end - it 'EmsFolder tooltip with %2f' do - ems_folder = FactoryGirl.create(:ems_folder, :name => 'foo %2f bar') - node = TreeNodeBuilder.build(ems_folder, nil, {}) - expect(node[:tooltip]).to eq('Folder: foo / bar') + it "LdapRegion node" do + region = FactoryGirl.build(:ldap_region) + node = TreeNodeBuilder.build(region, nil, {}) + expect(node).to eq( + :key => "-#{region.name}", + :title => "Region: #{region.name}", + :icon => "100/ldap_region.png", + :tooltip => "LDAP Region: #{region.name}", + :expand => false + ) end it 'MiqAeClass node' do namespace = FactoryGirl.build(:miq_ae_namespace) aclass = FactoryGirl.build(:miq_ae_class, :namespace_id => namespace.id) node = TreeNodeBuilder.build(aclass, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{aclass.name}", + :title => aclass.name, + :icon => "100/ae_class.png", + :tooltip => "Automate Class: #{aclass.name}", + :expand => false + ) end it 'MiqAeInstance node' do instance = FactoryGirl.build(:miq_ae_instance) node = TreeNodeBuilder.build(instance, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{instance.name}", + :title => instance.name, + :icon => "100/ae_instance.png", + :tooltip => "Automate Instance: #{instance.name}", + :expand => false + ) + end + + it 'MiqAeMethod node' do + method = FactoryGirl.build(:miq_ae_method) + node = TreeNodeBuilder.build(method, nil, {}) + expect(node).to eq( + :key => "-#{method.name}", + :title => method.name, + :icon => "100/ae_method.png", + :tooltip => "Automate Method: #{method.name}", + :expand => false + ) end it 'MiqAeNamespace node' do @@ -157,26 +559,46 @@ namespace = FactoryGirl.build(:miq_ae_namespace, :parent_id => 123) node = TreeNodeBuilder.build(namespace, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{namespace.name}", + :title => namespace.name, + :icon => "100/ae_namespace.png", + :tooltip => "Automate Namespace: #{namespace.name}", + :expand => false + ) end it 'MiqAlertSet node' do set = FactoryGirl.build(:miq_alert_set) node = TreeNodeBuilder.build(set, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{set.name}", + :title => set.name, + :icon => "100/miq_alert_profile.png", + :expand => false + ) end it 'MiqReport node' do report = FactoryGirl.build(:miq_report) node = TreeNodeBuilder.build(report, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{report.name}", + :title => report.name, + :icon => "100/report.png", + :expand => false + ) end it 'MiqReportResult node' do report_result = FactoryGirl.create(:miq_report_result) node = TreeNodeBuilder.build(report_result, nil, {}) - expect(node).not_to be_nil - expect(node[:icon]).to eq(ActionController::Base.helpers.image_path('100/report_result.png')) + expect(node).to eq( + :key => "rr-#{compress_id(report_result.id)}", + :title => "", + :icon => "100/report_result.png", + :expand => false + ) end it 'MiqSchedule node' do @@ -185,167 +607,509 @@ allow(MiqServer).to receive(:my_server).and_return(server) schedule = FactoryGirl.build(:miq_schedule) node = TreeNodeBuilder.build(schedule, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{schedule.name}", + :title => schedule.name, + :icon => "100/miq_schedule.png", + :expand => false + ) + end + + it "MiqScsiLun node" do + scsi_lun = FactoryGirl.create(:miq_scsi_lun, :canonical_name => 'foo') + node = TreeNodeBuilder.build(scsi_lun, nil, {}) + expect(node).to eq( + :key => "sl-#{compress_id(scsi_lun.id)}", + :title => scsi_lun.canonical_name, + :icon => "100/lun.png", + :tooltip => "LUN: #{scsi_lun.canonical_name}", + :expand => false + ) + end + + it "MiqScsiTarget node" do + scsi_target = FactoryGirl.create(:miq_scsi_target) + node = TreeNodeBuilder.build(scsi_target, nil, {}) + name = "SCSI Target #{scsi_target.target} (#{scsi_target.iscsi_name})" + expect(node).to eq( + :key => "sg-#{compress_id(scsi_target.id)}", + :title => name, + :icon => "100/target_scsi.png", + :tooltip => "Target: #{name}", + :expand => false + ) end it 'MiqServer node' do zone = FactoryGirl.build(:zone) server = FactoryGirl.build(:miq_server, :zone => zone) node = TreeNodeBuilder.build(server, nil, {}) - expect(node).not_to be_nil - end - - it 'MiqTemplate node' do - template = FactoryGirl.build(:miq_template, :name => "template", :location => "abc/abc.vmtx", :template => true, :vendor => "vmware") - node = TreeNodeBuilder.build(template, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{server.name}", + :title => "Server: #{server.name} []", + :icon => "100/miq_server.png", + :tooltip => "Server: #{server.name} []", + :expand => true + ) end it 'MiqAlert node' do alert = FactoryGirl.build(:miq_alert) node = TreeNodeBuilder.build(alert, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{alert.name}", + :title => alert.description, + :icon => "100/miq_alert.png", + :expand => false + ) end it 'MiqAction node' do action = FactoryGirl.build(:miq_action, :name => "raise_automation_event") node = TreeNodeBuilder.build(action, nil, {:tree => :action_tree}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{action.name}", + :title => action.description, + :icon => "100/miq_action_Test.png", + :expand => false + ) end it 'MiqEventDefinition node' do event = FactoryGirl.build(:miq_event_definition) node = TreeNodeBuilder.build(event, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{event.name}", + :title => event.description, + :icon => "100/event-#{event.name}.png", + :expand => false + ) end it 'MiqGroup node' do group = FactoryGirl.build(:miq_group) node = TreeNodeBuilder.build(group, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{group.name}", + :title => group.name, + :icon => "100/group.png", + :expand => false + ) end it 'MiqPolicy node' do policy = FactoryGirl.create(:miq_policy, :towhat => 'Vm', :active => true, :mode => 'control') node = TreeNodeBuilder.build(policy, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "p-#{compress_id(policy.id)}", + :title => policy.description, + :icon => "100/miq_policy_vm.png", + :expand => false + ) end it 'MiqPolicySet node' do policy_set = FactoryGirl.build(:miq_policy_set, :name => 'Just a set') node = TreeNodeBuilder.build(policy_set, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{policy_set.name}", + :title => policy_set.description, + :icon => "100/policy_profile_inactive.png", + :expand => false + ) end it 'MiqUserRole node' do role = FactoryGirl.build(:miq_user_role) node = TreeNodeBuilder.build(role, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{role.name}", + :title => role.name, + :icon => "100/miq_user_role.png", + :expand => false + ) end - it 'PxeImage node' do - image = FactoryGirl.build(:pxe_image) - node = TreeNodeBuilder.build(image, nil, {}) - expect(node).not_to be_nil + + it "OrchestrationTemplateCfn node" do + template = FactoryGirl.build(:orchestration_template_cfn) + node = TreeNodeBuilder.build(template, nil, {}) + expect(node).to eq( + :key => "-#{template.name}", + :title => template.name, + :icon => "100/orchestration_template_cfn.png", + :expand => false + ) + end + + it "OrchestrationTemplateHot node" do + template = FactoryGirl.build(:orchestration_template_hot_with_content) + node = TreeNodeBuilder.build(template, nil, {}) + expect(node).to eq( + :key => "-#{template.name}", + :title => template.name, + :icon => "100/orchestration_template_hot.png", + :expand => false + ) end - it 'WindowsImage node' do + it "OrchestrationTemplateAzure node" do + template = FactoryGirl.build(:orchestration_template_azure_with_content) + node = TreeNodeBuilder.build(template, nil, {}) + expect(node).to eq( + :key => "-#{template.name}", + :title => template.name, + :icon => "100/orchestration_template_azure.png", + :expand => false + ) + end + + it "OrchestrationTemplateVnfd node" do + template = FactoryGirl.build(:orchestration_template_vnfd_with_content) + node = TreeNodeBuilder.build(template, nil, {}) + expect(node).to eq( + :key => "-#{template.name}", + :title => template.name, + :icon => "100/orchestration_template_vnfd.png", + :expand => false + ) + end + + it "ManageIQ::Providers::Vmware::CloudManager::OrchestrationTemplate node" do + template = FactoryGirl.build(:orchestration_template_vmware_cloud) + node = TreeNodeBuilder.build(template, nil, {}) + expect(node).to eq( + :key => "-#{template.name}", + :title => template.name, + :icon => "100/orchestration_template_vapp.png", + :expand => false + ) + end + + context "PxeImage node" do + %w(pxe_image pxe_image_ipxe pxe_image_pxelinux).each do |factory| + it factory.classify do + image = FactoryGirl.build(factory) + node = TreeNodeBuilder.build(image, nil, {}) + expect(node).to eq( + :key => "-#{image.name}", + :title => image.name, + :icon => "100/pxeimage.png", + :expand => false + ) + end + end + end + + it "WindowsImage node" do image = FactoryGirl.build(:windows_image) node = TreeNodeBuilder.build(image, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{image.name}", + :title => image.name, + :icon => "100/os-windows_generic.png", + :expand => false + ) end - it 'PxeImageType node' do + it "PxeImageType node" do image_type = FactoryGirl.create(:pxe_image_type, :name => 'foo') node = TreeNodeBuilder.build(image_type, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "pit-#{compress_id(image_type.id)}", + :title => image_type.name, + :icon => "100/pxeimagetype.png", + :expand => false + ) end - it 'PxeServer node' do + it "PxeServer node" do server = FactoryGirl.build(:pxe_server) node = TreeNodeBuilder.build(server, nil, {}) - expect(node).not_to be_nil - end - - it 'Service node' do - service = FactoryGirl.create(:service) - node = TreeNodeBuilder.build(service, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{server.name}", + :title => server.name, + :icon => "100/pxeserver.png", + :expand => false + ) end - it 'ServiceResource node' do + context "Service node" do + %w( + service_template + service_template_ansible_tower + service_template_orchestration + ).each do |factory| + it factory.classify do + service = FactoryGirl.create(:service) + node = TreeNodeBuilder.build(service, nil, {}) + expect(node).to eq( + :key => "s-#{compress_id(service.id)}", + :title => service.name, + :icon => "100/service.png", + :expand => false + ) + end + end + end + + it "ServiceResource node" do resource = FactoryGirl.create(:service_resource) node = TreeNodeBuilder.build(resource, nil, {}) - expect(node).not_to be_nil - end - - it 'ServiceTemplate node' do - template = FactoryGirl.build(:service_template, - :name => 'test template', - :tenant => FactoryGirl.create(:tenant)) - node = TreeNodeBuilder.build(template, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "sr-#{compress_id(resource.id)}", + :title => resource.resource_name, + :icon => "100/service_template.png", + :expand => false + ) end - it 'ServiceTemplateCatalog node' do + context "ServiceTemplate node" do + %w( + service_template + service_template_ansible_tower + service_template_orchestration + ).each do |factory| + it factory.classify do + template = FactoryGirl.build(factory, + :name => "test template", + :tenant => FactoryGirl.create(:tenant)) + node = TreeNodeBuilder.build(template, nil, {}) + expect(node).to eq( + :key => "-#{template.name}", + :title => "#{template.name} (#{template.tenant.name})", + :icon => "100/service_template.png", + :expand => false + ) + end + end + end + + it "ServiceTemplateCatalog node" do catalog = FactoryGirl.build(:service_template_catalog, - :name => 'test template catalog', - :tenant => FactoryGirl.create(:tenant)) + :name => "test template catalog", + :tenant => FactoryGirl.create(:tenant)) node = TreeNodeBuilder.build(catalog, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{catalog.name}", + :title => "#{catalog.name} (#{catalog.tenant.name})", + :icon => "100/service_template_catalog.png", + :expand => false + ) + end + + it "Snapshot node" do + snapshot = FactoryGirl.build(:snapshot, :name => "Polaroid Picture") + node = TreeNodeBuilder.build(snapshot, nil, {}) + expect(node).to eq( + :key => "-#{snapshot.name}", + :title => snapshot.name, + :icon => "100/snapshot.png", + :tooltip => snapshot.name, + :expand => false + ) end - it 'Storage node' do + it "Storage node" do storage = FactoryGirl.build(:storage) node = TreeNodeBuilder.build(storage, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{storage.name}", + :title => storage.name, + :icon => "100/storage.png", + :expand => false + ) + end + + it "Switch node" do + switch = FactoryGirl.build(:switch, :name => "Lights") + node = TreeNodeBuilder.build(switch, nil, {}) + expect(node).to eq( + :key => "-#{switch.name}", + :title => switch.name, + :icon => "100/switch.png", + :tooltip => "Switch: #{switch.name}", + :expand => false + ) end - it 'User node' do + it "User node" do user = FactoryGirl.build(:user) node = TreeNodeBuilder.build(user, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{user.name}", + :title => user.name, + :icon => "100/user.png", + :expand => false + ) end - it 'MiqDialog node' do + it "MiqSearch node" do + search = FactoryGirl.build(:miq_search) + node = TreeNodeBuilder.build(search, nil, {}) + expect(node).to eq( + :key => "-#{search.name}", + :title => search.description, + :icon => "100/filter.png", + :tooltip => "Filter: #{search.description}", + :expand => false + ) + end + + it "MiqDialog node" do dialog = FactoryGirl.build(:miq_dialog) node = TreeNodeBuilder.build(dialog, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{dialog.name}", + :title => dialog.description, + :icon => "100/miqdialog.png", + :expand => false + ) end - it 'MiqRegion node' do + it "MiqRegion node" do region = FactoryGirl.build(:miq_region, :description => 'Elbonia') node = TreeNodeBuilder.build(region, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{region.name}", + :title => region.description, + :icon => "100/miq_region.png", + :expand => true + ) end - it 'MiqWidget node' do + it "MiqWidget node" do widget = FactoryGirl.build(:miq_widget) node = TreeNodeBuilder.build(widget, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{widget.name}", + :title => widget.title, + :icon => "100/#{widget.content_type}_widget.png", + :tooltip => widget.title, + :expand => false + ) end - it 'MiqWidgetSet node' do + it "MiqWidgetSet node" do widget_set = FactoryGirl.build(:miq_widget_set, :name => 'foo') node = TreeNodeBuilder.build(widget_set, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{widget_set.name}", + :title => widget_set.name, + :icon => "100/dashboard.png", + :tooltip => widget_set.name, + :expand => false + ) end - it 'VmdbTableEvm node' do - table = FactoryGirl.build(:vmdb_table_evm, :name => 'a table') + it "VmdbTableEvm node" do + table = FactoryGirl.build(:vmdb_table_evm, :name => "a table") node = TreeNodeBuilder.build(table, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "-#{table.name}", + :title => table.name, + :icon => "100/vmdbtableevm.png", + :expand => false + ) end - it 'VmdbIndex node' do - index = FactoryGirl.create(:vmdb_index, :name => 'foo') + it "VmdbIndex node" do + index = FactoryGirl.create(:vmdb_index, :name => "foo") node = TreeNodeBuilder.build(index, nil, {}) - expect(node).not_to be_nil + expect(node).to eq( + :key => "ti-#{compress_id(index.id)}", + :title => index.name, + :icon => "100/vmdbindex.png", + :expand => false + ) end - it 'Zone node' do - zone = FactoryGirl.build(:zone, :name => 'foo') + context "VmOrTemplate node" do + # Template classes + { + :miq_template => "Base", + :template_cloud => "ManageIQ::Providers::CloudManager::Template", + :template_infra => "ManageIQ::Providers::InfraManager::Template", + :template_amazon => "ManageIQ::Providers::Amazon::CloudManager::Template", + :template_azure => "ManageIQ::Providers::Azure::CloudManager::Template", + :template_google => "ManageIQ::Providers::Google::CloudManager::Template", + :template_openstack => "ManageIQ::Providers::Openstack::CloudManager::Template", + :template_vmware_cloud => "ManageIQ::Providers::Vmware::CloudManager::Template", + :template_microsoft => "ManageIQ::Providers::Microsoft::InfraManager::Template", + :template_redhat => "ManageIQ::Providers::Microsoft::InfraManager::Template", + :template_vmware => "ManageIQ::Providers::Vmware::InfraManager::Template", + :template_xen => "TemplateXen", + }.each do |factory, vm_type| + it vm_type do + template = FactoryGirl.build(factory, :name => "template", :template => true) + node = TreeNodeBuilder.build(template, nil, {}) + expect(node).to eq( + :key => "-#{template.name}", + :title => template.name, + :icon => "100/currentstate-archived.png", + :expand => false + ) + end + end + + # Vm classes + { + :vm => "Base", + :vm_cloud => "ManageIQ::Providers::CloudManager::Vm", + :vm_infra => "ManageIQ::Providers::InfraManager::Vm", + :vm_server => "VmServer", + :vm_amazon => "ManageIQ::Providers::Amazon::CloudManager::Vm", + :vm_azure => "ManageIQ::Providers::Azure::CloudManager::Vm", + :vm_google => "ManageIQ::Providers::Google::CloudManager::Vm", + :vm_openstack => "ManageIQ::Providers::Openstack::CloudManager::Vm", + :vm_vmware_cloud => "ManageIQ::Providers::Vmware::CloudManager::Vm", + :vm_microsoft => "ManageIQ::Providers::Microsoft::InfraManager::Vm", + :vm_redhat => "ManageIQ::Providers::Redhat::InfraManager::Vm", + :vm_vmware => "ManageIQ::Providers::Vmware::InfraManager::Vm", + :vm_xen => "VmXen", + }.each do |factory, vm_type| + it vm_type do + vm = FactoryGirl.build(factory) + node = TreeNodeBuilder.build(vm, nil, {}) + expect(node).to eq( + :key => "-#{vm.name}", + :title => vm.name, + :icon => "100/currentstate-archived.png", + :tooltip => "VM: #{vm.name} (Click to view)", + :expand => false + ) + end + end + + it "Vm node with /" do + vm = FactoryGirl.create(:vm_amazon, :name => "foo / bar") + node = TreeNodeBuilder.build(vm, "foo", {}) + expect(node[:title]).to eq("foo / bar") + end + + it "Vm node with %2f" do + vm = FactoryGirl.create(:vm_amazon, :name => "foo %2f bar") + node = TreeNodeBuilder.build(vm, nil, {}) + expect(node[:title]).to eq("foo / bar") + end + + it "Vm node with tooltip" do + vm = FactoryGirl.create(:vm_amazon, :name => "name") + node = TreeNodeBuilder.build(vm, nil, {}) + expect(node[:tooltip]).to eq(_("VM: %{name} (Click to view)") % {:name => vm.name}) + end + end + + it "Zone node" do + zone = FactoryGirl.build(:zone, :name => "foo") node = TreeNodeBuilder.build(zone, nil, {}) - expect(node).not_to be_nil + name = "Zone: #{zone.description}" + expect(node).to eq( + :key => "-#{zone.name}", + :title => name, + :icon => "100/zone.png", + :tooltip => name, + :expand => false + ) end it "expand attribute of node should be set to true when open_all is true and expand is nil in options" do