Merge "Remove deprecated swift::test_file"

This commit is contained in:
Zuul 2022-08-01 11:08:19 +00:00 committed by Gerrit Code Review
commit 0b2ab8214f
4 changed files with 4 additions and 224 deletions

View File

@ -1,50 +0,0 @@
# == Class: swift::test_file
#
# DEPRECATED !!
# Deploys a file that can be used to verify your swift installation.
#
# === Parameters
#
# [*password*]
# password used with tenant/user combination against auth_server. Required.
# [*auth_server*]
# server hosting keystone. Optional. Defaults to 127.0.0.1.
# [*tenant*]
# tenant used for authentication (required for retrieval of catalog). Optional. Defaults to openstack.
# [*user*]
# authenticated user. Optional. Defaults to 'admin'.
#
# === Examples
#
# class { 'swift::test_file':
# auth_server => '172.16.0.25',
# tenant => 'services',
# user => 'swift',
# password => 'admin_password',
# }
#
# === Authors
#
# Dan Bode <bodepd@gmail.com>
#
# === Copyright
#
# Copyright 2011 PuppetLabs.
#
class swift::test_file (
$password,
$auth_server = '127.0.0.1',
$tenant = 'openstack',
$user = 'admin'
) {
include swift::deps
warning('The swift::test_file class is deprecated and will be removed in a future release.')
file { '/tmp/swift_test_file.rb':
mode => '0755',
content => template('swift/swift_keystone_test.erb'),
tag => 'swift-file',
}
}

View File

@ -0,0 +1,4 @@
---
upgrade:
- |
The ``swift::test_file`` class has been removed.

View File

@ -1,59 +0,0 @@
require 'spec_helper'
describe 'swift::test_file' do
let :default_params do
{:password => 'foo'}
end
shared_examples 'swift::test_file' do
describe 'with defaults' do
let :params do
default_params
end
it 'should create a reasonable test file' do
verify_contents(catalogue, '/tmp/swift_test_file.rb',
[
'proxy_local_net_ip="127.0.0.1"',
"user='openstack:admin'",
"password='foo'"
]
)
end
end
describe 'when overriding' do
let :params do
default_params.merge({
:auth_server => '127.0.0.2',
:tenant => 'tenant',
:user => 'user',
:password => 'password'
})
end
it 'should create a configured test file' do
verify_contents(catalogue, '/tmp/swift_test_file.rb',
[
'proxy_local_net_ip="127.0.0.2"',
"user='tenant:user'",
"password='password'"
]
)
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge(OSDefaults.get_facts())
end
it_configures 'swift::test_file'
end
end
end

View File

@ -1,115 +0,0 @@
#!/usr/bin/env ruby
#
# This is a script that uses
# instructions here: https://docs.openstack.org/swift/latest/howto_installmultinode.html
# Even though I expect this script will work with a wide range
# of swift versions, it is currently only tested with: 1.4.6
require 'open3'
require 'fileutils'
# connection variables
proxy_local_net_ip="<%= @auth_server %>"
user='<%= @tenant %>:<%= @user %>'
password='<%= @password %>'
## headers for curl requests
#user_header="-H 'X-Storage-User: #{user}'"
#password_header="-H 'X-Storage-Pass: #{password}'"
#get_cred_command="curl -k -v #{user_header} #{password_header} http://#{proxy_local_net_ip}:5000/v2.0/"
#
## verify that we can retrieve credentials from our user
#result_hash = {}
#puts "getting credentials: #{get_cred_command}"
#Open3.popen3(get_cred_command) do |stdin, stdout, stderr|
# result_hash[:stderr] = stderr.read
# result_hash[:stderr].split("\n").each do |line|
# if line =~ /^< HTTP\/\d\.\d (\d\d\d)/
# result_hash[:status_code]=$1
# end
# if line =~ /< X-Storage-Url: (http\S+)/
# result_hash[:auth_url]=$1
# end
# if line =~ /< X-Storage-Token: (AUTH_\S+)/
# result_hash[:auth_token]=$1
# end
# end
#end
#raise(Exception, "Call to get auth tokens failed:\n#{result_hash[:stderr]}") unless result_hash[:status_code] == '200'
#
## verify that the credentials are valid
#auth_token_header="-H 'X-Auth-Token: #{result_hash[:auth_token]}'"
#puts auth_token_header
#get_account_head="curl -k -v #{auth_token_header} #{result_hash[:auth_url]}"
## what is the expected code?
#puts "verifying connection auth: #{get_account_head}"
#Open3.popen3(get_account_head) do |stdin, stdout, stderr|
# #puts stdout.read
# #puts stderr.read
#end
swift_command_prefix="swift -A http://#{proxy_local_net_ip}:5000/v2.0/ -V 2 -U #{user} -K #{password}"
swift_test_command="#{swift_command_prefix} stat"
puts "Testing swift: #{swift_test_command}"
status_hash={}
Open3.popen3(swift_test_command) do |stdin, stdout, stderr|
status_hash[:stdout] = stdout.read
status_hash[:stderr] = stderr.read
status_hash[:stdout].split("\n").each do |line|
if line =~ /\s*Containers:\s+(\d+)/
status_hash[:containers] = $1
end
if line =~ /\s*Objects:\s+(\d+)/
status_hash[:objects] = $1
end
end
end
unless(status_hash[:containers] =~ /\d+/ and status_hash[:objects] =~ /\d+/)
raise(Exception, "Expected to find the number of containers/objects:\n#{status_hash[:stdout]}\n#{status_hash[:stderr]}")
else
puts "found containers/objects: #{status_hash[:containers]}/#{status_hash[:objects]}"
end
# test that we can upload something
File.open('/tmp/foo1', 'w') do |fh|
fh.write('test1')
end
container = 'my_container'
swift_upload_command="#{swift_command_prefix} upload #{container} /tmp/foo1"
puts "Uploading file to swift with command: #{swift_upload_command}"
Open3.popen3(swift_upload_command) do |stdin, stdout, stderr|
puts stdout.read
puts stderr.read
end
# test that we can download the thing that we uploaded
download_test_dir = '/tmp/test/downloadtest/'
FileUtils.rm_rf download_test_dir
FileUtils.mkdir_p download_test_dir
swift_download_command="#{swift_command_prefix} download #{container}"
puts "Downloading file with command: #{swift_download_command}"
Dir.chdir(download_test_dir) do
Open3.popen3(swift_download_command) do |stdin, stdout, stderr|
puts stdout.read
puts stderr.read
end
end
expected_file = File.join(download_test_dir, 'tmp', 'foo1')
if File.exists?(expected_file)
if File.read(expected_file) == 'test1'
puts "Dude!!!! It actually seems to work, we can upload and download files!!!!"
else
raise(Exception, "So close, but the contents of the downloaded file are not what I expected: Got: #{File.read(expected_file)}, expected: test1")
end
else
raise(Exception, "file #{expected_file} did not exist somehow, probably b/c swift is not installed correctly")
end