<commit_before>#! /usr/bin/env ruby

require 'spec_helper'
require 'yaml'
require 'puppet/util/network_device/brocade_fos/device'
require 'puppet/provider/brocade_fos'
require 'puppet/util/network_device/transport_fos/ssh'

describe "Integration test for brocade zone membership" do

  device_conf =  YAML.load_file(my_deviceurl('brocade','device_conf.yml'))

  before :each do
    Facter.stubs(:value).with(:url).returns(device_conf['url'])
  end

  let :zone_add_member do
    Puppet::Type.type(:brocade_zone_membership).new(
    :zonename    => 'testZone',
    :ensure      => 'present',
    :member      => 'fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b',
    )
  end

  let :zone_delete_member do
    Puppet::Type.type(:brocade_zone_membership).new(
    :zonename    => 'testZone',
    :ensure      => 'absent',
    :member      => 'fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b',
    )
  end
  
    let :create_zone do
    Puppet::Type.type(:brocade_zone).new(
    :zonename     => 'testZone',
    :ensure   => 'present',
    :member => 'fc00:db20:35b:7399::5',
    )
  end

  context "should add and remove member to a zone" do
    it "should should add a member to a zone" do
      create_zone.provider.device_transport.connect
      zone_remove_res = create_zone.provider.device_transport.command("zonedelete #{create_zone[:zonename]}", :noop=>false)
      cfg_save_res = create_zone.provider.device_transport.command("cfgsave",:prompt => /Do/)
      if cfg_save_res.match(/fail|err|not found|not an alias/)
        puts "Unable to save the Config because of the following issue: #{cfg_save_res}"
      else
        puts "Successfully saved the Config"
      end
      create_zone.provider.device_transport.close
     
      create_zone.provider.device_transport.connect
      zone_create_res = create_zone.provider.create
      
      ##Executing test below
      zone_add_member.provider.device_transport.connect
      zone_add_member.provider.create
      zone_show_res = zone_add_member.provider.device_transport.command(get_zone_show_cmd(zone_add_member[:zonename]),:noop=>false)
      zone_add_member.provider.device_transport.close
      presense?(zone_show_res,zone_add_member[:member]).should == true
    end

    it "should delete a member from a zone" do
      zone_delete_member.provider.device_transport.connect
      zone_show_res = zone_delete_member.provider.device_transport.command(get_zone_show_cmd(zone_delete_member[:zonename]),:noop=>false)
      if presense?(zone_show_res,zone_delete_member[:member]) == false
        ##If member is not present in the zone, add the member and continue the test
        zone_mem_add_res = zone_delete_member.provider.device_transport.command("zoneadd \"#{zone_delete_member[:member]}\"",:noop=>false)
        cfg_save_res = zone_delete_member.provider.device_transport.command("cfgsave",:prompt => /Do/)
        if cfg_save_res.match(/fail|err|not found|not an alias/)
          puts "Unable to save the Config because of the following issue: #{cfg_save_res}"
        else
          puts "Successfully saved the Config"
        end
      end
      zone_delete_member.provider.device_transport.close
      zone_delete_member.provider.device_transport.connect
      zone_delete_member.provider.destroy
      zone_show_res = zone_delete_member.provider.device_transport.command(get_zone_show_cmd(zone_delete_member[:zonename]),:noop=>false)
      zone_delete_member.provider.device_transport.close
      presense?(zone_show_res,zone_delete_member[:member]).should == false
    end

  end

  def presense?(response_string,key_to_check)
    retval = false
    if response_string.include?("#{key_to_check}")
    retval = true
    else
    retval = false
    end
    return retval
  end

  def get_zone_show_cmd(zonename)
    command = "zoneshow #{zonename}"
  end
end
<commit_msg>brocade_zone_membership_spec.rb is modified as per review comments.<commit_after>#! /usr/bin/env ruby

require 'spec_helper'
require 'yaml'
require 'puppet/util/network_device/brocade_fos/device'
require 'puppet/provider/brocade_fos'
require 'puppet/util/network_device/transport_fos/ssh'

describe "Integration test for brocade zone membership" do

  device_conf =  YAML.load_file(my_deviceurl('brocade','device_conf.yml'))

  before :each do
    Facter.stubs(:value).with(:url).returns(device_conf['url'])
  end

  let :zone_add_member do
    Puppet::Type.type(:brocade_zone_membership).new(
    :zonename    => 'testZone',
    :ensure      => 'present',
    :member      => 'fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b',
    )
  end

  let :zone_delete_member do
    Puppet::Type.type(:brocade_zone_membership).new(
    :zonename    => 'testZone',
    :ensure      => 'absent',
    :member      => 'fd00:a516:7c1b:17cd:6d81:2137:bd2a:2c5b',
    )
  end
  
    let :create_zone do
    Puppet::Type.type(:brocade_zone).new(
    :zonename     => 'testZone',
    :ensure   => 'present',
    :member => 'fc00:db20:35b:7399::5',
    )
  end
    let :destroy_zone do
    Puppet::Type.type(:brocade_zone).new(
    :zonename => 'testZone',
    :ensure   => 'absent',
    )
  end
    
  
  before :each do
    puts "Creating Zone before Test"
    create_zone.provider.device_transport.connect
    create_zone.provider.create
    create_zone.provider.device_transport.close
  end

  after :each do
    puts "Delete Zone after Test"
    destroy_zone.provider.device_transport.connect
    destroy_zone.provider.destroy
    destroy_zone.provider.device_transport.close
  end

  context "should add and remove member to a zone" do
    it "should should add a member to a zone" do
      zone_add_member.provider.device_transport.connect
      zone_add_member.provider.create
      zone_show_res = zone_add_member.provider.device_transport.command(get_zone_show_cmd(zone_add_member[:zonename]),:noop=>false)
      puts "zone_show_res after adding member:#{zone_show_res}"
      zone_add_member.provider.device_transport.close
      presense?(zone_show_res,zone_add_member[:member]).should == true
    end

    it "should delete a member from a zone" do
      zone_delete_member.provider.device_transport.connect
      zone_delete_member.provider.destroy
      zone_show_res = zone_delete_member.provider.device_transport.command(get_zone_show_cmd(zone_delete_member[:zonename]),:noop=>false)
      zone_delete_member.provider.device_transport.close
      presense?(zone_show_res,zone_delete_member[:member]).should_not == true
    end
  end

  def presense?(response_string,key_to_check)
    retval = false
    if response_string.include?("#{key_to_check}")
    retval = true
    else
    retval = false
    end
    return retval
  end

  def get_zone_show_cmd(zonename)
    command = "zoneshow #{zonename}"
  end
end

{'fraction_non_alphanumeric': 0.10597502972651605, 'fraction_numerical': 0.014565992865636148, 'mean_word_length': 3.883164005805515, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '4049180', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2231, 'n_words': 394}